Skip to content

Commit 1bf9e22

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

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
@@ -153,7 +160,22 @@ impl fmt::Display for ShaderError<naga::WithSpan<naga::valid::ValidationError>>
153160
let config = term::Config::default();
154161
let mut writer = term::termcolor::NoColor::new(Vec::new());
155162

156-
let diagnostic = Diagnostic::error().with_labels(
163+
let err_chain = {
164+
let mut msg_buf = String::new();
165+
write!(msg_buf, "{}", self.inner).unwrap();
166+
167+
let mut source = self.inner.source();
168+
while let Some(next) = source {
169+
// NOTE: The spacing here matters for presentation as a `Diagnostic`. Formula used:
170+
//
171+
// * 7 spaces to offset `error: `
172+
// * 2 more spaces for "compact" indentation of the original error
173+
writeln!(msg_buf, " {next}").unwrap();
174+
source = next.source();
175+
}
176+
msg_buf
177+
};
178+
let diagnostic = Diagnostic::error().with_message(err_chain).with_labels(
157179
self.inner
158180
.spans()
159181
.map(|&(span, ref desc)| {

0 commit comments

Comments
 (0)