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

+18
View File
@@ -10,6 +10,7 @@ use crate::{
AttachmentData, MissingDownlevelFlags, MissingFeatures, RenderPassCompatibilityError,
RenderPassContext,
},
error::{ErrorFormatter, PrettyError},
hub::{Global, GlobalIdentityHandlerFactory, HalApi, Storage, Token},
id,
memory_init_tracker::{MemoryInitKind, MemoryInitTrackerAction},
@@ -458,6 +459,15 @@ pub enum RenderPassErrorInner {
QueryUse(#[from] QueryUseError),
}
impl PrettyError for RenderPassErrorInner {
fn fmt_pretty(&self, fmt: &mut ErrorFormatter) {
fmt.error(self);
if let Self::InvalidAttachment(id) = *self {
fmt.texture_view_label_with_key(&id, "attachment");
};
}
}
impl From<MissingBufferUsageError> for RenderPassErrorInner {
fn from(error: MissingBufferUsageError) -> Self {
Self::RenderCommand(error.into())
@@ -478,6 +488,14 @@ pub struct RenderPassError {
#[source]
inner: RenderPassErrorInner,
}
impl PrettyError for RenderPassError {
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, RenderPassError> for Result<T, E>
where