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 Feb 8, 2024
1 parent 7908e46 commit 356ca8a
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions wgpu-core/src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -140,7 +147,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 356ca8a

Please sign in to comment.