From 9cbcd934908d7df9164ca29922e222fe6afe74b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emil=20Gardstr=C3=B6m?= Date: Thu, 17 Mar 2022 22:22:58 +0100 Subject: [PATCH 1/4] add config option to disable location section --- src/config.rs | 22 ++++++++++++++++++++++ src/handler.rs | 18 ++++++++++-------- src/lib.rs | 2 ++ tests/location_disabled.rs | 16 ++++++++++++++++ 4 files changed, 50 insertions(+), 8 deletions(-) create mode 100644 tests/location_disabled.rs diff --git a/src/config.rs b/src/config.rs index 0a12444..ed8f306 100644 --- a/src/config.rs +++ b/src/config.rs @@ -418,6 +418,8 @@ pub struct HookBuilder { filters: Vec>, capture_span_trace_by_default: bool, display_env_section: bool, + #[cfg(feature = "track-caller")] + display_location_section: bool, panic_section: Option>, panic_message: Option>, theme: Theme, @@ -459,6 +461,8 @@ impl HookBuilder { filters: vec![], capture_span_trace_by_default: false, display_env_section: true, + #[cfg(feature = "track-caller")] + display_location_section: true, panic_section: None, panic_message: None, theme: Theme::dark(), @@ -649,6 +653,18 @@ impl HookBuilder { 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 /// /// # Examples @@ -723,6 +739,8 @@ impl HookBuilder { #[cfg(feature = "capture-spantrace")] capture_span_trace_by_default: self.capture_span_trace_by_default, display_env_section: self.display_env_section, + #[cfg(feature = "track-caller")] + display_location_section: self.display_location_section, theme, #[cfg(feature = "issue-url")] issue_url: self.issue_url, @@ -1000,6 +1018,8 @@ pub struct EyreHook { #[cfg(feature = "capture-spantrace")] capture_span_trace_by_default: bool, display_env_section: bool, + #[cfg(feature = "track-caller")] + display_location_section: bool, theme: Theme, #[cfg(feature = "issue-url")] issue_url: Option, @@ -1034,6 +1054,8 @@ impl EyreHook { span_trace, sections: Vec::new(), display_env_section: self.display_env_section, + #[cfg(feature = "track-caller")] + display_location_section: self.display_location_section, #[cfg(feature = "issue-url")] issue_url: self.issue_url.clone(), #[cfg(feature = "issue-url")] diff --git a/src/handler.rs b/src/handler.rs index 3f2a1a1..cbd2d07 100644 --- a/src/handler.rs +++ b/src/handler.rs @@ -69,14 +69,16 @@ impl eyre::EyreHandler for Handler { let mut separated = f.header("\n\n"); #[cfg(feature = "track-caller")] - write!( - separated.ready(), - "{}", - crate::SectionExt::header( - crate::fmt::LocationSection(self.location, self.theme), - "Location:" - ) - )?; + if self.display_location_section { + write!( + separated.ready(), + "{}", + crate::SectionExt::header( + crate::fmt::LocationSection(self.location, self.theme), + "Location:" + ) + )?; + } for section in self .sections diff --git a/src/lib.rs b/src/lib.rs index 2acf68a..056dbde 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -404,6 +404,8 @@ pub struct Handler { span_trace: Option, sections: Vec, display_env_section: bool, + #[cfg(feature = "track-caller")] + display_location_section: bool, #[cfg(feature = "issue-url")] issue_url: Option, #[cfg(feature = "issue-url")] diff --git a/tests/location_disabled.rs b/tests/location_disabled.rs new file mode 100644 index 0000000..7eee57c --- /dev/null +++ b/tests/location_disabled.rs @@ -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:")); +} From 5890bab17660bd0a2b4fb33187d210282258c99b Mon Sep 17 00:00:00 2001 From: Jane Lusby Date: Mon, 11 Jul 2022 15:55:30 -0700 Subject: [PATCH 2/4] fix clippy warnings --- src/config.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/config.rs b/src/config.rs index ed8f306..40a079c 100644 --- a/src/config.rs +++ b/src/config.rs @@ -207,7 +207,9 @@ impl<'a> fmt::Display for StyledFrame<'a> { let name = frame.name.as_deref().unwrap_or(""); let has_hash_suffix = name.len() > 19 && &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 { &name[name.len() - 19..] @@ -924,7 +926,7 @@ fn print_panic_info(report: &PanicReport<'_>, f: &mut fmt::Formatter<'_>) -> fmt Ok(()) } -impl<'a, 'b> fmt::Display for PanicReport<'a> { +impl fmt::Display for PanicReport<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { print_panic_info(self, f) } From 6ebf8453ea8755bfc6baf6234930803e833f71df Mon Sep 17 00:00:00 2001 From: Jane Lusby Date: Mon, 11 Jul 2022 16:04:26 -0700 Subject: [PATCH 3/4] Update changelog for new release --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d292772..06a30a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] - ReleaseDate +### Added +- Option to disable display of location section in error reports ## [0.6.1] - 2022-02-24 ### Changed From 6a9b70b44d11e0540b9dbc325149bab2a5d505b6 Mon Sep 17 00:00:00 2001 From: Jane Lusby Date: Mon, 11 Jul 2022 16:06:14 -0700 Subject: [PATCH 4/4] (cargo-release) version 0.6.2 --- CHANGELOG.md | 5 ++++- Cargo.toml | 2 +- src/lib.rs | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 06a30a9..6d34f89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] - ReleaseDate + +## [0.6.2] - 2022-07-11 ### Added - Option to disable display of location section in error reports @@ -70,7 +72,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 better compatibility with the Display trait -[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.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 diff --git a/Cargo.toml b/Cargo.toml index 1085b5f..146da11 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "color-eyre" -version = "0.6.1" +version = "0.6.2" authors = ["Jane Lusby "] edition = "2018" license = "MIT OR Apache-2.0" diff --git a/src/lib.rs b/src/lib.rs index 056dbde..f80f8cc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -334,7 +334,7 @@ //! [`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/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))] #![warn( missing_docs,