mirror of
https://github.com/eyre-rs/eyre.git
synced 2025-09-28 05:21:34 +00:00
Merge pull request #113 from chris-laplante/cpl/suppress_backtrace
add `suppress_backtrace` method
This commit is contained in:
commit
4a7b4d6988
@ -1059,6 +1059,7 @@ impl EyreHook {
|
||||
crate::Handler {
|
||||
filters: self.filters.clone(),
|
||||
backtrace,
|
||||
suppress_backtrace: false,
|
||||
#[cfg(feature = "capture-spantrace")]
|
||||
span_trace,
|
||||
sections: Vec::new(),
|
||||
|
@ -113,14 +113,17 @@ impl eyre::EyreHandler for Handler {
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(backtrace) = self.backtrace.as_ref() {
|
||||
let fmted_bt = self.format_backtrace(backtrace);
|
||||
if !self.suppress_backtrace {
|
||||
if let Some(backtrace) = self.backtrace.as_ref() {
|
||||
let fmted_bt = self.format_backtrace(backtrace);
|
||||
|
||||
write!(
|
||||
indented(&mut separated.ready()).with_format(Format::Uniform { indentation: " " }),
|
||||
"{}",
|
||||
fmted_bt
|
||||
)?;
|
||||
write!(
|
||||
indented(&mut separated.ready())
|
||||
.with_format(Format::Uniform { indentation: " " }),
|
||||
"{}",
|
||||
fmted_bt
|
||||
)?;
|
||||
}
|
||||
}
|
||||
|
||||
let f = separated.ready();
|
||||
|
@ -400,6 +400,7 @@ mod writers;
|
||||
pub struct Handler {
|
||||
filters: Arc<[Box<config::FilterCallback>]>,
|
||||
backtrace: Option<Backtrace>,
|
||||
suppress_backtrace: bool,
|
||||
#[cfg(feature = "capture-spantrace")]
|
||||
span_trace: Option<SpanTrace>,
|
||||
sections: Vec<HelpInfo>,
|
||||
|
@ -142,6 +142,14 @@ impl Section for Report {
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
fn suppress_backtrace(mut self, suppress: bool) -> Self::Return {
|
||||
if let Some(handler) = self.handler_mut().downcast_mut::<crate::Handler>() {
|
||||
handler.suppress_backtrace = suppress;
|
||||
}
|
||||
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, E> Section for Result<T, E>
|
||||
@ -234,6 +242,11 @@ where
|
||||
self.map_err(|error| error.into())
|
||||
.map_err(|report| report.error(error()))
|
||||
}
|
||||
|
||||
fn suppress_backtrace(self, suppress: bool) -> Self::Return {
|
||||
self.map_err(|error| error.into())
|
||||
.map_err(|report| report.suppress_backtrace(suppress))
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) enum HelpInfo {
|
||||
|
@ -315,6 +315,12 @@ pub trait Section: crate::private::Sealed {
|
||||
where
|
||||
D: Display + Send + Sync + 'static,
|
||||
F: FnOnce() -> D;
|
||||
|
||||
/// Whether to suppress printing of collected backtrace (if any).
|
||||
///
|
||||
/// Useful for reporting "unexceptional" errors for which a backtrace
|
||||
/// isn't really necessary.
|
||||
fn suppress_backtrace(self, suppress: bool) -> Self::Return;
|
||||
}
|
||||
|
||||
/// Trait for printing a panic error message for the given PanicInfo
|
||||
|
Loading…
x
Reference in New Issue
Block a user