Skip to content

Commit 8f263c7

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

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
@@ -118,7 +125,22 @@ impl fmt::Display for ShaderError<naga::WithSpan<naga::valid::ValidationError>>
118125
let config = term::Config::default();
119126
let mut writer = term::termcolor::NoColor::new(Vec::new());
120127

121-
let diagnostic = Diagnostic::error().with_labels(
128+
let err_chain = {
129+
let mut msg_buf = String::new();
130+
write!(msg_buf, "{}", self.inner).unwrap();
131+
132+
let mut source = self.inner.source();
133+
while let Some(next) = source {
134+
// NOTE: The spacing here matters for presentation as a `Diagnostic`. Formula used:
135+
//
136+
// * 7 spaces to offset `error: `
137+
// * 2 more spaces for "compact" indentation of the original error
138+
writeln!(msg_buf, " {next}").unwrap();
139+
source = next.source();
140+
}
141+
msg_buf
142+
};
143+
let diagnostic = Diagnostic::error().with_message(err_chain).with_labels(
122144
self.inner
123145
.spans()
124146
.map(|&(span, ref desc)| {

0 commit comments

Comments
 (0)