diff --git a/src/backend/direct.rs b/src/backend/direct.rs index a8c92c63e..5f3adb1bb 100644 --- a/src/backend/direct.rs +++ b/src/backend/direct.rs @@ -1419,7 +1419,10 @@ impl crate::Context for Context { ) { let global = &self.0; wgc::gfx_select!(encoder.id => global.command_encoder_run_render_pass(encoder.id, pass)) - .map_err(|err| err.with_context("In a RenderPass", None)) + .map_err(|err| { + let name = wgc::gfx_select!(encoder.id => global.command_buffer_label(encoder.id)); + err.with_context_label_key("In a render pass", "encoder", Some(&name)) + }) .unwrap_error_sink(&encoder.error_sink, &self, || ()) } @@ -1578,15 +1581,29 @@ where } trait WithContextError: Error + Send + Sync + 'static + Sized { - fn with_context(self, string: &str, label: Option<&str>) -> ContextError; + fn with_context_label_key( + self, + string: &str, + label_key: &'static str, + label: Option<&str>, + ) -> ContextError; + fn with_context(self, string: &str, label: Option<&str>) -> ContextError { + self.with_context_label_key(string, "label", label) + } } impl WithContextError for E { - fn with_context(self, string: &str, label: Option<&str>) -> ContextError { + fn with_context_label_key( + self, + string: &str, + label_key: &'static str, + label: Option<&str>, + ) -> ContextError { ContextError { string: string.to_string(), cause: Box::new(self), label: label.unwrap_or("").to_string(), + label_key, } } } @@ -1595,6 +1612,7 @@ impl WithContextError for E { pub(crate) struct ContextError { pub string: String, pub cause: Box, + pub label_key: &'static str, pub label: String, } diff --git a/src/backend/error.rs b/src/backend/error.rs index 92bd1335a..0158964f8 100644 --- a/src/backend/error.rs +++ b/src/backend/error.rs @@ -82,7 +82,7 @@ pub trait PrettyError: Error { impl PrettyError for super::direct::ContextError { fn fmt_pretty(&self, _context: &Context) -> String { - format_error_line(self.as_display()) + &format_label_line("label", &self.label) + format_error_line(self.as_display()) + &format_label_line(self.label_key, &self.label) } }