From 28912feb00795207c8d081aad884e2a3dfaab9d4 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Mon, 21 Oct 2024 11:04:17 -0400 Subject: [PATCH] fix(naga-cli): reimpl. `emit_annotated_error` with `WithSpan::emit_to_stderr_with_path` --- CHANGELOG.md | 1 + naga-cli/src/bin/naga.rs | 33 ++++++++------------------------- 2 files changed, 9 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 311968ab0..0aa9793ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -87,6 +87,7 @@ By @bradwerth [#6216](https://github.com/gfx-rs/wgpu/pull/6216). - Support polyfilling `inverse` in WGSL. By @chyyran in [#6385](https://github.com/gfx-rs/wgpu/pull/6385). - Add an internal skeleton for parsing `requires`, `enable`, and `diagnostic` directives that don't yet do anything besides emit nicer errors. By @ErichDonGubler in [#6352](https://github.com/gfx-rs/wgpu/pull/6352). - Include error chain information as a message and notes in shader compilation messages. By @ErichDonGubler in [#6436](https://github.com/gfx-rs/wgpu/pull/6436). +- Unify Naga CLI error output with the format of shader compilation messages. By @ErichDonGubler in [#6436](https://github.com/gfx-rs/wgpu/pull/6436). #### General diff --git a/naga-cli/src/bin/naga.rs b/naga-cli/src/bin/naga.rs index 8cec1801c..f9a061361 100644 --- a/naga-cli/src/bin/naga.rs +++ b/naga-cli/src/bin/naga.rs @@ -517,8 +517,9 @@ fn run() -> anyhow::Result<()> { 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(&error); } - print_err(&error); None } }; @@ -545,8 +546,9 @@ fn run() -> anyhow::Result<()> { 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(&error); } - print_err(&error); None } } @@ -870,8 +872,9 @@ fn bulk_validate(args: Args, params: &Parameters) -> anyhow::Result<()> { if let Some(input) = &input_text { let filename = path.file_name().and_then(std::ffi::OsStr::to_str); emit_annotated_error(&error, filename.unwrap_or("input"), input); + } else { + print_err(&error); } - print_err(&error); } } @@ -892,29 +895,9 @@ fn bulk_validate(args: Args, params: &Parameters) -> anyhow::Result<()> { Ok(()) } -use codespan_reporting::{ - diagnostic::{Diagnostic, Label}, - files::SimpleFile, - term::{ - self, - termcolor::{ColorChoice, StandardStream}, - }, -}; +use codespan_reporting::term::termcolor::{ColorChoice, StandardStream}; use naga::{FastHashMap, WithSpan}; pub fn emit_annotated_error(ann_err: &WithSpan, filename: &str, source: &str) { - let files = SimpleFile::new(filename, source); - let config = codespan_reporting::term::Config::default(); - let writer = StandardStream::stderr(ColorChoice::Auto); - - let diagnostic = Diagnostic::error().with_labels( - ann_err - .spans() - .map(|(span, desc)| { - Label::primary((), span.to_range().unwrap()).with_message(desc.to_owned()) - }) - .collect(), - ); - - term::emit(&mut writer.lock(), &config, &files, &diagnostic).expect("cannot write error"); + ann_err.emit_to_stderr_with_path(source, filename); }