Skip to content

Commit

Permalink
Merge branch 'master' into cpl/suppress_backtrace
Browse files Browse the repository at this point in the history
  • Loading branch information
yaahc authored Aug 1, 2022
2 parents 2821e2b + ad68589 commit 93fcb6f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Add the following to your toml file:

```toml
[dependencies]
color-eyre = "0.5"
color-eyre = "0.6"
```

And install the panic and error report handlers:
Expand All @@ -49,7 +49,7 @@ tracing integration to cut down on unused dependencies:

```toml
[dependencies]
color-eyre = { version = "0.5", default-features = false }
color-eyre = { version = "0.6", default-features = false }
```

### Disabling SpanTrace capture by default
Expand Down
13 changes: 10 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::{
section::PanicMessage,
writers::{EnvSection, WriterExt},
};
use eyre::WrapErr;
use fmt::Display;
use indenter::{indented, Format};
use owo_colors::{style, OwoColorize, Style};
Expand Down Expand Up @@ -700,7 +701,7 @@ impl HookBuilder {

/// Install the given Hook as the global error report hook
pub fn install(self) -> Result<(), crate::eyre::Report> {
let (panic_hook, eyre_hook) = self.into_hooks();
let (panic_hook, eyre_hook) = self.try_into_hooks()?;
eyre_hook.install()?;
panic_hook.install();
Ok(())
Expand All @@ -715,6 +716,12 @@ impl HookBuilder {
/// Create a `PanicHook` and `EyreHook` from this `HookBuilder`.
/// This can be used if you want to combine these handlers with other handlers.
pub fn into_hooks(self) -> (PanicHook, EyreHook) {
self.try_into_hooks().expect("into_hooks should only be called when no `color_spantrace` themes have previously been set")
}

/// Create a `PanicHook` and `EyreHook` from this `HookBuilder`.
/// This can be used if you want to combine these handlers with other handlers.
pub fn try_into_hooks(self) -> Result<(PanicHook, EyreHook), crate::eyre::Report> {
let theme = self.theme;
#[cfg(feature = "issue-url")]
let metadata = Arc::new(self.issue_metadata);
Expand Down Expand Up @@ -753,9 +760,9 @@ impl HookBuilder {
};

#[cfg(feature = "capture-spantrace")]
color_spantrace::set_theme(self.theme.into()).expect("could not set the provided `Theme` via `color_spantrace::set_theme` globally as another was already set");
color_spantrace::set_theme(self.theme.into()).wrap_err("could not set the provided `Theme` via `color_spantrace::set_theme` globally as another was already set")?;

(panic_hook, eyre_hook)
Ok((panic_hook, eyre_hook))
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
//!
//! ```toml
//! [dependencies]
//! color-eyre = "0.5"
//! color-eyre = "0.6"
//! ```
//!
//! And install the panic and error report handlers:
Expand All @@ -56,7 +56,7 @@
//!
//! ```toml
//! [dependencies]
//! color-eyre = { version = "0.5", default-features = false }
//! color-eyre = { version = "0.6", default-features = false }
//! ```
//!
//! ### Disabling SpanTrace capture by default
Expand Down
7 changes: 7 additions & 0 deletions tests/install.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use color_eyre::install;

#[test]
fn double_install_should_not_panic() {
install().unwrap();
assert!(install().is_err());
}

0 comments on commit 93fcb6f

Please sign in to comment.