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'm using eyre as my error handler and trying to write a custom error handler using eyre hook
Basically, a backtrace will be captured when error happens, and will be printed/logged later when handling the error.
The problem is that I want to capture the backtrace as unresolved and resolve it later in my custom handler so that passing the error around is cheaper. However, I'm not able to do this because, in order to use resolve, my captured backtrace must be a mutable reference. I also tried to get the backtrace frames and resolve each one manually, but I encountered the same issue: the backtrace frames are not &mut, and the Frame field of BacktraceFrame is not exported to use resolve_symbols method.
Proposed Solution
Can BacktraceFrame also have resolve_symbols which call frame.resolve_symbols and return all symbols that have been resolved? It already have symbols method but they are empty if the captured backtrace was unresolved
Example code
structHook{capture_backtrace:bool,}implHook{fnmake_handler(&self,_error:&(dynError + 'static)) -> Handler{let backtrace = ifself.capture_backtrace{Some(Backtrace::new_unresolved())}else{None};Handler{ backtrace }}}structHandler{// custom configured backtrace capturebacktrace:Option<Backtrace>,}implEyreHandlerforHandler{fndebug(&self,error:&(dynError + 'static),f:&mut fmt::Formatter<'_>) -> fmt::Result{if f.alternate(){return fmt::Debug::fmt(error, f);}let errors = iter::successors(Some(error), |error| (*error).source());for(ind, error)in errors.enumerate(){write!(f,"\n{:>4}: {}", ind, error)?;}ifletSome(backtrace) = self.backtrace.as_ref(){writeln!(f,"\n\nBacktrace:\n{:?}", backtrace)?;let frames = backtrace.frames();for(ind, frame)in frames.iter().enumerate(){writeln!(f,"\n{:>4}: {:?}", ind, frame.resolve())?;// cannot resolve because frame is not &mut// My workaround// let ip = frame.ip();// backtrace::resolve(ip, |symbol| {// println!("{:?}", symbol);// });// Proposed solution// let backtrace_symbols = frame.resolve_symbols();// println!("{:?}", backtrace_symbols);}}Ok(())}}
The text was updated successfully, but these errors were encountered:
Problem
unresolved
and resolve it later in my custom handler so that passing the error around is cheaper. However, I'm not able to do this because, in order to use resolve, my captured backtrace must be a mutable reference. I also tried to get the backtrace frames and resolve each one manually, but I encountered the same issue: the backtrace frames are not &mut, and theFrame
field ofBacktraceFrame
is not exported to useresolve_symbols
method.Proposed Solution
BacktraceFrame
also haveresolve_symbols
which callframe.resolve_symbols
and return all symbols that have been resolved? It already havesymbols
method but they are empty if the captured backtrace wasunresolved
Example code
The text was updated successfully, but these errors were encountered: