fix(naga-cli): reimpl. emit_annotated_error with WithSpan::emit_to_stderr_with_path

This commit is contained in:
Erich Gubler 2024-10-21 11:04:17 -04:00
parent 6f43ee9f17
commit 28912feb00
2 changed files with 9 additions and 25 deletions

View File

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

View File

@ -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<E: Error>(ann_err: &WithSpan<E>, 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);
}