You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am adding an attachment called Type to my error reporting library:
/// wrapper attachment that is used to refer to the type of an object/// rather than the valuepubstructType(&'static str);implType{// const fn when `std::any::type_name` is const fn in stablepubfnof<T>() -> Self{Self(std::any::type_name::<T>())}}impl std::fmt::DisplayforType{fnfmt(&self,f:&mut std::fmt::Formatter<'_>) -> std::fmt::Result{write!(f, "<{}>", self.0)}}impl std::fmt::DebugforType{fnfmt(&self,f:&mut std::fmt::Formatter<'_>) -> std::fmt::Result{
f.debug_tuple("Type").field(&self.0).finish()}}
I would like to evaluate the colour mode for each attachment that I display:
The suggested approach for dealing with conditional formatting is use HookContext data from within Report::install_debug_hook::<Type>, the issue here is that it requires an explicit invocation for each attachment type anytime you might use the attachment.
Location, Backtrace and SpanTrace do not need to declare debug hooks since they have a prelude that calls the hooks for them error_stack::fmt::hook::default::install_builtin_hooks:
I'm curious if there's a good way to allow attachments to define their own conditional formatting and have them be instantiated into the prelude along with the builtin types.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I am adding an attachment called
Type
to my error reporting library:I would like to evaluate the colour mode for each attachment that I display:
The suggested approach for dealing with conditional formatting is use
HookContext
data from withinReport::install_debug_hook::<Type>
, the issue here is that it requires an explicit invocation for each attachment type anytime you might use the attachment.Location
,Backtrace
andSpanTrace
do not need to declare debug hooks since they have a prelude that calls the hooks for themerror_stack::fmt::hook::default::install_builtin_hooks
:hash/libs/error-stack/src/fmt/hook.rs
Lines 497 to 507 in 1c930a0
I'm curious if there's a good way to allow attachments to define their own conditional formatting and have them be instantiated into the prelude along with the builtin types.
Beta Was this translation helpful? Give feedback.
All reactions