Error formatting impls closer to errors

This is achieved by making a ErrorFormatter helper that is passed to
fmt_pretty, making the impls a lot simpler.
This commit is contained in:
Mikko Lehtonen authored and Dzmitry Malyshau committed 2021-08-03 11:51:52 -04:00
1 parent e4cdddc639
commit 019dca3cfa
9 files changed
+300 -239

No files matched your search

+20
View File
@@ -43,6 +43,7 @@ use crate::{
AttachmentData, Device, DeviceError, MissingDownlevelFlags, RenderPassContext,
SHADER_STAGE_COUNT,
},
error::{ErrorFormatter, PrettyError},
hub::{GlobalIdentityHandlerFactory, HalApi, Hub, Resource, Storage, Token},
id,
memory_init_tracker::{MemoryInitKind, MemoryInitTrackerAction},
@@ -560,6 +561,17 @@ pub enum ExecutionError {
#[error("using {0} in a render bundle is not implemented")]
Unimplemented(&'static str),
}
impl PrettyError for ExecutionError {
fn fmt_pretty(&self, fmt: &mut ErrorFormatter) {
fmt.error(self);
match *self {
Self::DestroyedBuffer(id) => {
fmt.buffer_label(&id);
}
Self::Unimplemented(_reason) => {}
};
}
}
pub type RenderBundleDescriptor<'a> = wgt::RenderBundleDescriptor<Label<'a>>;
@@ -1161,6 +1173,14 @@ impl RenderBundleError {
inner: RenderBundleErrorInner::Device(DeviceError::Invalid),
};
}
impl PrettyError for RenderBundleError {
fn fmt_pretty(&self, fmt: &mut ErrorFormatter) {
// This error is wrapper for the inner error,
// but the scope has useful labels
fmt.error(self);
self.scope.fmt_pretty(fmt);
}
}
impl<T, E> MapPassErr<T, RenderBundleError> for Result<T, E>
where