Merge pull request #113 from chris-laplante/cpl/suppress_backtrace

add `suppress_backtrace` method
This commit is contained in:
Jane Losare-Lusby 2022-08-03 19:37:19 -07:00 committed by GitHub
commit 4a7b4d6988
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 7 deletions

View File

@ -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(),

View File

@ -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();

View File

@ -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>,

View File

@ -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 {

View File

@ -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