Skip to content

Commit ec1f042

Browse files
refactor(core)!: fold Error source chain Display output into shader errors
1 parent a10e626 commit ec1f042

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

wgpu-core/src/pipeline.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,14 @@ use crate::{
1010
resource_log, validation, Label,
1111
};
1212
use arrayvec::ArrayVec;
13-
use std::{borrow::Cow, error::Error, fmt, marker::PhantomData, num::NonZeroU32, sync::Arc};
13+
use std::{
14+
borrow::Cow,
15+
error::Error,
16+
fmt::{self, Write},
17+
marker::PhantomData,
18+
num::NonZeroU32,
19+
sync::Arc,
20+
};
1421
use thiserror::Error;
1522

1623
/// Information about buffer bindings, which
@@ -140,7 +147,22 @@ impl fmt::Display for ShaderError<naga::WithSpan<naga::valid::ValidationError>>
140147
let config = term::Config::default();
141148
let mut writer = term::termcolor::NoColor::new(Vec::new());
142149

143-
let diagnostic = Diagnostic::error().with_labels(
150+
let err_chain = {
151+
let mut msg_buf = String::new();
152+
write!(msg_buf, "{}", self.inner).unwrap();
153+
154+
let mut source = self.inner.source();
155+
while let Some(next) = source {
156+
// NOTE: The spacing here matters for presentation as a `Diagnostic`. Formula used:
157+
//
158+
// * 7 spaces to offset `error: `
159+
// * 2 more spaces for "compact" indentation of the original error
160+
writeln!(msg_buf, " {next}").unwrap();
161+
source = next.source();
162+
}
163+
msg_buf
164+
};
165+
let diagnostic = Diagnostic::error().with_message(err_chain).with_labels(
144166
self.inner
145167
.spans()
146168
.map(|&(span, ref desc)| {

0 commit comments

Comments
 (0)