Skip to content

Commit

Permalink
efactor(cli): generate Diagnostic::message from print_err inside …
Browse files Browse the repository at this point in the history
…`emit_annotated_error`
  • Loading branch information
ErichDonGubler committed Apr 26, 2023
1 parent 8ef254a commit e1d42b8
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions cli/src/bin/naga.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,9 @@ fn run() -> Result<(), Box<dyn std::error::Error>> {
if let Some(input) = input_text {
let filename = input_path.file_name().and_then(std::ffi::OsStr::to_str);
emit_annotated_error(&error, filename.unwrap_or("input"), &input);
} else {
print_err(&mut stderr().lock(), &error);
}
print_err(&mut stderr().lock(), &error);
None
}
};
Expand Down Expand Up @@ -557,7 +558,14 @@ pub fn emit_annotated_error<E: Error>(ann_err: &WithSpan<E>, filename: &str, sou
let config = codespan_reporting::term::Config::default();
let writer = StandardStream::stderr(ColorChoice::Auto);

let diagnostic = Diagnostic::error().with_labels(
let mut msg_buf = Vec::new();
print_err(&mut msg_buf, ann_err);
let msg = String::from_utf8(msg_buf)
.unwrap()
// NOTE: `replace` is intended to correct the alignment of multi-line messages against the
// `error: ` prefix, which is 7 characters.
.replace("\n", "\n ");
let diagnostic = Diagnostic::error().with_message(msg).with_labels(
ann_err
.spans()
.map(|(span, desc)| {
Expand Down

0 comments on commit e1d42b8

Please sign in to comment.