Merge branch 'yaahc:master' into cpl/suppress_backtrace

This commit is contained in:
Chris Laplante 2022-07-21 16:50:38 -04:00 committed by GitHub
commit 99df70d21f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 62 additions and 13 deletions

View File

@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] - ReleaseDate ## [Unreleased] - ReleaseDate
## [0.6.2] - 2022-07-11
### Added
- Option to disable display of location section in error reports
## [0.6.1] - 2022-02-24 ## [0.6.1] - 2022-02-24
### Changed ### Changed
- Collapsed backtrace help text into fewer lines - Collapsed backtrace help text into fewer lines
@ -68,7 +72,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
better compatibility with the Display trait better compatibility with the Display trait
<!-- next-url --> <!-- next-url -->
[Unreleased]: https://github.com/yaahc/color-eyre/compare/v0.6.1...HEAD [Unreleased]: https://github.com/yaahc/color-eyre/compare/v0.6.2...HEAD
[0.6.2]: https://github.com/yaahc/color-eyre/compare/v0.6.1...v0.6.2
[0.6.1]: https://github.com/yaahc/color-eyre/compare/v0.6.0...v0.6.1 [0.6.1]: https://github.com/yaahc/color-eyre/compare/v0.6.0...v0.6.1
[0.6.0]: https://github.com/yaahc/color-eyre/compare/v0.5.11...v0.6.0 [0.6.0]: https://github.com/yaahc/color-eyre/compare/v0.5.11...v0.6.0
[0.5.11]: https://github.com/yaahc/color-eyre/compare/v0.5.10...v0.5.11 [0.5.11]: https://github.com/yaahc/color-eyre/compare/v0.5.10...v0.5.11

View File

@ -1,6 +1,6 @@
[package] [package]
name = "color-eyre" name = "color-eyre"
version = "0.6.1" version = "0.6.2"
authors = ["Jane Lusby <jlusby@yaah.dev>"] authors = ["Jane Lusby <jlusby@yaah.dev>"]
edition = "2018" edition = "2018"
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"

View File

@ -207,7 +207,9 @@ impl<'a> fmt::Display for StyledFrame<'a> {
let name = frame.name.as_deref().unwrap_or("<unknown>"); let name = frame.name.as_deref().unwrap_or("<unknown>");
let has_hash_suffix = name.len() > 19 let has_hash_suffix = name.len() > 19
&& &name[name.len() - 19..name.len() - 16] == "::h" && &name[name.len() - 19..name.len() - 16] == "::h"
&& name[name.len() - 16..].chars().all(|x| x.is_digit(16)); && name[name.len() - 16..]
.chars()
.all(|x| x.is_ascii_hexdigit());
let hash_suffix = if has_hash_suffix { let hash_suffix = if has_hash_suffix {
&name[name.len() - 19..] &name[name.len() - 19..]
@ -418,6 +420,8 @@ pub struct HookBuilder {
filters: Vec<Box<FilterCallback>>, filters: Vec<Box<FilterCallback>>,
capture_span_trace_by_default: bool, capture_span_trace_by_default: bool,
display_env_section: bool, display_env_section: bool,
#[cfg(feature = "track-caller")]
display_location_section: bool,
panic_section: Option<Box<dyn Display + Send + Sync + 'static>>, panic_section: Option<Box<dyn Display + Send + Sync + 'static>>,
panic_message: Option<Box<dyn PanicMessage>>, panic_message: Option<Box<dyn PanicMessage>>,
theme: Theme, theme: Theme,
@ -459,6 +463,8 @@ impl HookBuilder {
filters: vec![], filters: vec![],
capture_span_trace_by_default: false, capture_span_trace_by_default: false,
display_env_section: true, display_env_section: true,
#[cfg(feature = "track-caller")]
display_location_section: true,
panic_section: None, panic_section: None,
panic_message: None, panic_message: None,
theme: Theme::dark(), theme: Theme::dark(),
@ -649,6 +655,18 @@ impl HookBuilder {
self self
} }
/// Configures the location info section and whether or not it is displayed.
///
/// # Notes
///
/// This will not disable the location section in a panic message.
#[cfg(feature = "track-caller")]
#[cfg_attr(docsrs, doc(cfg(feature = "track-caller")))]
pub fn display_location_section(mut self, cond: bool) -> Self {
self.display_location_section = cond;
self
}
/// Add a custom filter to the set of frame filters /// Add a custom filter to the set of frame filters
/// ///
/// # Examples /// # Examples
@ -723,6 +741,8 @@ impl HookBuilder {
#[cfg(feature = "capture-spantrace")] #[cfg(feature = "capture-spantrace")]
capture_span_trace_by_default: self.capture_span_trace_by_default, capture_span_trace_by_default: self.capture_span_trace_by_default,
display_env_section: self.display_env_section, display_env_section: self.display_env_section,
#[cfg(feature = "track-caller")]
display_location_section: self.display_location_section,
theme, theme,
#[cfg(feature = "issue-url")] #[cfg(feature = "issue-url")]
issue_url: self.issue_url, issue_url: self.issue_url,
@ -906,7 +926,7 @@ fn print_panic_info(report: &PanicReport<'_>, f: &mut fmt::Formatter<'_>) -> fmt
Ok(()) Ok(())
} }
impl<'a, 'b> fmt::Display for PanicReport<'a> { impl fmt::Display for PanicReport<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
print_panic_info(self, f) print_panic_info(self, f)
} }
@ -1000,6 +1020,8 @@ pub struct EyreHook {
#[cfg(feature = "capture-spantrace")] #[cfg(feature = "capture-spantrace")]
capture_span_trace_by_default: bool, capture_span_trace_by_default: bool,
display_env_section: bool, display_env_section: bool,
#[cfg(feature = "track-caller")]
display_location_section: bool,
theme: Theme, theme: Theme,
#[cfg(feature = "issue-url")] #[cfg(feature = "issue-url")]
issue_url: Option<String>, issue_url: Option<String>,
@ -1035,6 +1057,8 @@ impl EyreHook {
span_trace, span_trace,
sections: Vec::new(), sections: Vec::new(),
display_env_section: self.display_env_section, display_env_section: self.display_env_section,
#[cfg(feature = "track-caller")]
display_location_section: self.display_location_section,
#[cfg(feature = "issue-url")] #[cfg(feature = "issue-url")]
issue_url: self.issue_url.clone(), issue_url: self.issue_url.clone(),
#[cfg(feature = "issue-url")] #[cfg(feature = "issue-url")]

View File

@ -69,14 +69,16 @@ impl eyre::EyreHandler for Handler {
let mut separated = f.header("\n\n"); let mut separated = f.header("\n\n");
#[cfg(feature = "track-caller")] #[cfg(feature = "track-caller")]
write!( if self.display_location_section {
separated.ready(), write!(
"{}", separated.ready(),
crate::SectionExt::header( "{}",
crate::fmt::LocationSection(self.location, self.theme), crate::SectionExt::header(
"Location:" crate::fmt::LocationSection(self.location, self.theme),
) "Location:"
)?; )
)?;
}
for section in self for section in self
.sections .sections

View File

@ -334,7 +334,7 @@
//! [`examples/custom_filter.rs`]: https://github.com/yaahc/color-eyre/blob/master/examples/custom_filter.rs //! [`examples/custom_filter.rs`]: https://github.com/yaahc/color-eyre/blob/master/examples/custom_filter.rs
//! [`examples/custom_section.rs`]: https://github.com/yaahc/color-eyre/blob/master/examples/custom_section.rs //! [`examples/custom_section.rs`]: https://github.com/yaahc/color-eyre/blob/master/examples/custom_section.rs
//! [`examples/multiple_errors.rs`]: https://github.com/yaahc/color-eyre/blob/master/examples/multiple_errors.rs //! [`examples/multiple_errors.rs`]: https://github.com/yaahc/color-eyre/blob/master/examples/multiple_errors.rs
#![doc(html_root_url = "https://docs.rs/color-eyre/0.6.1")] #![doc(html_root_url = "https://docs.rs/color-eyre/0.6.2")]
#![cfg_attr(docsrs, feature(doc_cfg))] #![cfg_attr(docsrs, feature(doc_cfg))]
#![warn( #![warn(
missing_docs, missing_docs,
@ -405,6 +405,8 @@ pub struct Handler {
span_trace: Option<SpanTrace>, span_trace: Option<SpanTrace>,
sections: Vec<HelpInfo>, sections: Vec<HelpInfo>,
display_env_section: bool, display_env_section: bool,
#[cfg(feature = "track-caller")]
display_location_section: bool,
#[cfg(feature = "issue-url")] #[cfg(feature = "issue-url")]
issue_url: Option<String>, issue_url: Option<String>,
#[cfg(feature = "issue-url")] #[cfg(feature = "issue-url")]

View File

@ -0,0 +1,16 @@
#[cfg(feature = "track-caller")]
#[test]
fn disabled() {
use color_eyre::eyre;
use eyre::eyre;
color_eyre::config::HookBuilder::default()
.display_location_section(false)
.install()
.unwrap();
let report = eyre!("error occured");
let report = format!("{:?}", report);
assert!(!report.contains("Location:"));
}