mirror of
https://github.com/eyre-rs/eyre.git
synced 2025-09-30 22:42:02 +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 {
|
crate::Handler {
|
||||||
filters: self.filters.clone(),
|
filters: self.filters.clone(),
|
||||||
backtrace,
|
backtrace,
|
||||||
|
suppress_backtrace: false,
|
||||||
#[cfg(feature = "capture-spantrace")]
|
#[cfg(feature = "capture-spantrace")]
|
||||||
span_trace,
|
span_trace,
|
||||||
sections: Vec::new(),
|
sections: Vec::new(),
|
||||||
|
@ -113,14 +113,17 @@ impl eyre::EyreHandler for Handler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(backtrace) = self.backtrace.as_ref() {
|
if !self.suppress_backtrace {
|
||||||
let fmted_bt = self.format_backtrace(backtrace);
|
if let Some(backtrace) = self.backtrace.as_ref() {
|
||||||
|
let fmted_bt = self.format_backtrace(backtrace);
|
||||||
|
|
||||||
write!(
|
write!(
|
||||||
indented(&mut separated.ready()).with_format(Format::Uniform { indentation: " " }),
|
indented(&mut separated.ready())
|
||||||
"{}",
|
.with_format(Format::Uniform { indentation: " " }),
|
||||||
fmted_bt
|
"{}",
|
||||||
)?;
|
fmted_bt
|
||||||
|
)?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let f = separated.ready();
|
let f = separated.ready();
|
||||||
|
@ -400,6 +400,7 @@ mod writers;
|
|||||||
pub struct Handler {
|
pub struct Handler {
|
||||||
filters: Arc<[Box<config::FilterCallback>]>,
|
filters: Arc<[Box<config::FilterCallback>]>,
|
||||||
backtrace: Option<Backtrace>,
|
backtrace: Option<Backtrace>,
|
||||||
|
suppress_backtrace: bool,
|
||||||
#[cfg(feature = "capture-spantrace")]
|
#[cfg(feature = "capture-spantrace")]
|
||||||
span_trace: Option<SpanTrace>,
|
span_trace: Option<SpanTrace>,
|
||||||
sections: Vec<HelpInfo>,
|
sections: Vec<HelpInfo>,
|
||||||
|
@ -142,6 +142,14 @@ impl Section for Report {
|
|||||||
|
|
||||||
self
|
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>
|
impl<T, E> Section for Result<T, E>
|
||||||
@ -234,6 +242,11 @@ where
|
|||||||
self.map_err(|error| error.into())
|
self.map_err(|error| error.into())
|
||||||
.map_err(|report| report.error(error()))
|
.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 {
|
pub(crate) enum HelpInfo {
|
||||||
|
@ -315,6 +315,12 @@ pub trait Section: crate::private::Sealed {
|
|||||||
where
|
where
|
||||||
D: Display + Send + Sync + 'static,
|
D: Display + Send + Sync + 'static,
|
||||||
F: FnOnce() -> D;
|
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
|
/// Trait for printing a panic error message for the given PanicInfo
|
||||||
|
Loading…
x
Reference in New Issue
Block a user