diff options
| author | He Li <li@imlihe.com> | 2023-11-30 02:57:57 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-29 19:57:57 +0100 |
| commit | 3ea2ad6cae6211d1ab7c85a79c1c8ba7dcf55556 (patch) | |
| tree | 148986e9440343d9f15c0525ac6735afe83749f7 /crates | |
| parent | c580a31768020021943a0313596821fbd0eab34e (diff) | |
Don't exit watcher on invalid utf-8 (#2795)
Diffstat (limited to 'crates')
| -rw-r--r-- | crates/typst-cli/src/compile.rs | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/crates/typst-cli/src/compile.rs b/crates/typst-cli/src/compile.rs index 73115924..3397935b 100644 --- a/crates/typst-cli/src/compile.rs +++ b/crates/typst-cli/src/compile.rs @@ -6,7 +6,7 @@ use codespan_reporting::diagnostic::{Diagnostic, Label}; use codespan_reporting::term::{self, termcolor}; use ecow::eco_format; use termcolor::{ColorChoice, StandardStream}; -use typst::diag::{bail, Severity, SourceDiagnostic, StrResult}; +use typst::diag::{bail, At, Severity, SourceDiagnostic, StrResult}; use typst::eval::Tracer; use typst::foundations::Datetime; use typst::model::Document; @@ -78,8 +78,20 @@ pub fn compile_once( Status::Compiling.print(command).unwrap(); } - // Ensure that the main file is present. - world.source(world.main()).map_err(|err| err.to_string())?; + // Check if main file can be read and opened. + if let Err(errors) = world.source(world.main()).at(Span::detached()) { + set_failed(); + tracing::info!("Failed to open and decode main file"); + + if watching { + Status::Error.print(command).unwrap(); + } + + print_diagnostics(world, &errors, &[], command.common.diagnostic_format) + .map_err(|err| eco_format!("failed to print diagnostics ({err})"))?; + + return Ok(()); + } let mut tracer = Tracer::new(); let result = typst::compile(world, &mut tracer); |
