diff --git a/wgpu-core/src/pipeline.rs b/wgpu-core/src/pipeline.rs index 82a023bf031..92313877743 100644 --- a/wgpu-core/src/pipeline.rs +++ b/wgpu-core/src/pipeline.rs @@ -10,7 +10,14 @@ use crate::{ resource_log, validation, Label, }; use arrayvec::ArrayVec; -use std::{borrow::Cow, error::Error, fmt, marker::PhantomData, num::NonZeroU32, sync::Arc}; +use std::{ + borrow::Cow, + error::Error, + fmt::{self, Write}, + marker::PhantomData, + num::NonZeroU32, + sync::Arc, +}; use thiserror::Error; /// Information about buffer bindings, which @@ -153,7 +160,22 @@ impl fmt::Display for ShaderError> let config = term::Config::default(); let mut writer = term::termcolor::NoColor::new(Vec::new()); - let diagnostic = Diagnostic::error().with_labels( + let err_chain = { + 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)| {