Skip to content

Commit

Permalink
refactor(core)!: fold Error source chain Display output into shad…
Browse files Browse the repository at this point in the history
…er errors
  • Loading branch information
ErichDonGubler committed Jun 8, 2023
1 parent 92fae49 commit 958df3f
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions wgpu-core/src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ use crate::{
validation, Label, LifeGuard, Stored,
};
use arrayvec::ArrayVec;
use std::{borrow::Cow, error::Error, fmt, marker::PhantomData, num::NonZeroU32};
use std::{
borrow::Cow,
error::Error,
fmt::{self, Write},
marker::PhantomData,
num::NonZeroU32,
};
use thiserror::Error;

/// Information about buffer bindings, which
Expand Down Expand Up @@ -92,7 +98,22 @@ impl fmt::Display for ShaderError<naga::WithSpan<naga::valid::ValidationError>>
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)| {
Expand Down

0 comments on commit 958df3f

Please sign in to comment.