feat: exit if compile errors happen (#1512)

This commit is contained in:
Myriad-Dreamin 2025-03-16 16:41:04 +08:00 committed by GitHub
parent 3d83885778
commit 478842c6bc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 32 additions and 0 deletions

View file

@ -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

View file

@ -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?;