Skip to content

Commit 958df3f

Browse files
refactor(core)!: fold Error source chain Display output into shader errors
1 parent 92fae49 commit 958df3f

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

wgpu-core/src/pipeline.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ use crate::{
77
validation, Label, LifeGuard, Stored,
88
};
99
use arrayvec::ArrayVec;
10-
use std::{borrow::Cow, error::Error, fmt, marker::PhantomData, num::NonZeroU32};
10+
use std::{
11+
borrow::Cow,
12+
error::Error,
13+
fmt::{self, Write},
14+
marker::PhantomData,
15+
num::NonZeroU32,
16+
};
1117
use thiserror::Error;
1218

1319
/// Information about buffer bindings, which
@@ -92,7 +98,22 @@ impl fmt::Display for ShaderError<naga::WithSpan<naga::valid::ValidationError>>
9298
let config = term::Config::default();
9399
let mut writer = term::termcolor::NoColor::new(Vec::new());
94100

95-
let diagnostic = Diagnostic::error().with_labels(
101+
let err_chain = {
102+
let mut msg_buf = String::new();
103+
write!(msg_buf, "{}", self.inner).unwrap();
104+
105+
let mut source = self.inner.source();
106+
while let Some(next) = source {
107+
// NOTE: The spacing here matters for presentation as a `Diagnostic`. Formula used:
108+
//
109+
// * 7 spaces to offset `error: `
110+
// * 2 more spaces for "compact" indentation of the original error
111+
writeln!(msg_buf, " {next}").unwrap();
112+
source = next.source();
113+
}
114+
msg_buf
115+
};
116+
let diagnostic = Diagnostic::error().with_message(err_chain).with_labels(
96117
self.inner
97118
.spans()
98119
.map(|&(span, ref desc)| {

0 commit comments

Comments
 (0)