Skip to content

Commit

Permalink
refactor(naga)!: fold Error source chain Display output into shad…
Browse files Browse the repository at this point in the history
…er errors
  • Loading branch information
ErichDonGubler committed May 8, 2024
1 parent 626bf29 commit f6709f0
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion naga/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,24 @@ impl fmt::Display for ShaderError<crate::WithSpan<crate::valid::ValidationError>
let config = term::Config::default();
let mut writer = term::termcolor::NoColor::new(Vec::new());

let diagnostic = Diagnostic::error().with_labels(
let err_chain = {
use std::fmt::Write;

let mut msg_buf = String::new();
write!(msg_buf, "{}", self.inner).unwrap();

let mut source = self.inner.source();
while let Some(next) = source {
// NOTE: The spacing here matters for presentation as a `Diagnostic`. Formula used:
//
// * 7 spaces to offset `error: `
// * 2 more spaces for "compact" indentation of the original error
writeln!(msg_buf, " {next}").unwrap();
source = next.source();
}
msg_buf
};
let diagnostic = Diagnostic::error().with_message(err_chain).with_labels(
self.inner
.spans()
.map(|&(span, ref desc)| {
Expand Down

0 comments on commit f6709f0

Please sign in to comment.