Skip to content

Commit b331d23

Browse files
refactor(naga)!: fold Error source chain Display output into shader errors
1 parent ac2058b commit b331d23

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

naga/src/error.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,24 @@ impl fmt::Display for ShaderError<crate::WithSpan<crate::valid::ValidationError>
4848
let config = term::Config::default();
4949
let mut writer = termcolor::NoColor::new(Vec::new());
5050

51-
let diagnostic = Diagnostic::error().with_labels(
51+
let err_chain = {
52+
use std::fmt::Write;
53+
54+
let mut msg_buf = String::new();
55+
write!(msg_buf, "{}", self.inner).unwrap();
56+
57+
let mut source = self.inner.source();
58+
while let Some(next) = source {
59+
// NOTE: The spacing here matters for presentation as a `Diagnostic`. Formula used:
60+
//
61+
// * 7 spaces to offset `error: `
62+
// * 2 more spaces for "compact" indentation of the original error
63+
writeln!(msg_buf, " {next}").unwrap();
64+
source = next.source();
65+
}
66+
msg_buf
67+
};
68+
let diagnostic = Diagnostic::error().with_message(err_chain).with_labels(
5269
self.inner
5370
.spans()
5471
.map(|&(span, ref desc)| {

0 commit comments

Comments
 (0)