From ac2058ba9a8531f1996afec60eeab9dcfa2567bb Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Fri, 26 Jan 2024 13:00:19 -0500 Subject: [PATCH 1/2] style(naga): delimit `error`'s items with two newlines --- naga/src/error.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/naga/src/error.rs b/naga/src/error.rs index c5845e5fd6..7153b80541 100644 --- a/naga/src/error.rs +++ b/naga/src/error.rs @@ -16,6 +16,7 @@ impl fmt::Display for ShaderError { write!(f, "\nShader '{label}' parsing {string}") } } + #[cfg(feature = "glsl-in")] impl fmt::Display for ShaderError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -24,6 +25,7 @@ impl fmt::Display for ShaderError { write!(f, "\nShader '{label}' parsing {string}") } } + #[cfg(feature = "spv-in")] impl fmt::Display for ShaderError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -32,6 +34,7 @@ impl fmt::Display for ShaderError { write!(f, "\nShader '{label}' parsing {string}") } } + impl fmt::Display for ShaderError> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { use codespan_reporting::{ @@ -63,6 +66,7 @@ impl fmt::Display for ShaderError ) } } + impl Error for ShaderError where ShaderError: fmt::Display, From b331d237d23b42a775832c8ce09ca9c347207797 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Fri, 22 Dec 2023 14:25:09 -0500 Subject: [PATCH 2/2] refactor(naga)!: fold `Error` source chain `Display` output into shader errors --- naga/src/error.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/naga/src/error.rs b/naga/src/error.rs index 7153b80541..856e56eaa1 100644 --- a/naga/src/error.rs +++ b/naga/src/error.rs @@ -48,7 +48,24 @@ impl fmt::Display for ShaderError let config = term::Config::default(); let mut writer = 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)| {