mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-08-03 17:58:17 +00:00
feat: exit if compile errors happen (#1512)
This commit is contained in:
parent
3d83885778
commit
478842c6bc
2 changed files with 32 additions and 0 deletions
|
@ -162,6 +162,29 @@ impl<F: CompilerFeat> CompiledArtifact<F> {
|
|||
deps: OnceLock::default(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns error diagnostics.
|
||||
pub fn errors(&self) -> Option<&EcoVec<SourceDiagnostic>> {
|
||||
self.doc.as_ref().err()
|
||||
}
|
||||
|
||||
/// Returns warning diagnostics.
|
||||
pub fn warnings(&self) -> &EcoVec<SourceDiagnostic> {
|
||||
&self.warnings
|
||||
}
|
||||
|
||||
/// Returns whether there are any errors.
|
||||
pub fn has_errors(&self) -> bool {
|
||||
self.errors().is_some_and(|e| !e.is_empty())
|
||||
}
|
||||
|
||||
/// Returns whether there are any warnings.
|
||||
pub fn diagnostics(&self) -> impl Iterator<Item = &SourceDiagnostic> {
|
||||
self.errors()
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.chain(self.warnings.iter())
|
||||
}
|
||||
}
|
||||
|
||||
// todo: remove me
|
||||
|
|
|
@ -173,6 +173,15 @@ pub async fn compile_main(args: CompileArgs) -> Result<()> {
|
|||
// Compiles the project
|
||||
let compiled = CompiledArtifact::from_snapshot(snap);
|
||||
|
||||
let diag = compiled.diagnostics();
|
||||
print_diagnostics(&compiled.world, diag, DiagnosticFormat::Human)
|
||||
.context_ut("print diagnostics")?;
|
||||
|
||||
if compiled.has_errors() {
|
||||
// todo: we should process case of compile error in fn main function
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
||||
// Exports the compiled project
|
||||
let lock_dir = save_lock.then_some(lock_dir);
|
||||
ExportTask::do_export(output.task, compiled, lock_dir).await?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue