mirror of
https://github.com/eyre-rs/eyre.git
synced 2025-10-02 15:26:08 +00:00
fix: Do not panic on multiple install
calls
This commit is contained in:
parent
ede865079d
commit
48037df311
@ -4,6 +4,7 @@ use crate::{
|
|||||||
section::PanicMessage,
|
section::PanicMessage,
|
||||||
writers::{EnvSection, WriterExt},
|
writers::{EnvSection, WriterExt},
|
||||||
};
|
};
|
||||||
|
use eyre::WrapErr;
|
||||||
use fmt::Display;
|
use fmt::Display;
|
||||||
use indenter::{indented, Format};
|
use indenter::{indented, Format};
|
||||||
use owo_colors::{style, OwoColorize, Style};
|
use owo_colors::{style, OwoColorize, Style};
|
||||||
@ -700,7 +701,7 @@ impl HookBuilder {
|
|||||||
|
|
||||||
/// Install the given Hook as the global error report hook
|
/// Install the given Hook as the global error report hook
|
||||||
pub fn install(self) -> Result<(), crate::eyre::Report> {
|
pub fn install(self) -> Result<(), crate::eyre::Report> {
|
||||||
let (panic_hook, eyre_hook) = self.into_hooks();
|
let (panic_hook, eyre_hook) = self.into_hooks()?;
|
||||||
eyre_hook.install()?;
|
eyre_hook.install()?;
|
||||||
panic_hook.install();
|
panic_hook.install();
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -714,7 +715,7 @@ impl HookBuilder {
|
|||||||
|
|
||||||
/// Create a `PanicHook` and `EyreHook` from this `HookBuilder`.
|
/// Create a `PanicHook` and `EyreHook` from this `HookBuilder`.
|
||||||
/// This can be used if you want to combine these handlers with other handlers.
|
/// This can be used if you want to combine these handlers with other handlers.
|
||||||
pub fn into_hooks(self) -> (PanicHook, EyreHook) {
|
pub fn into_hooks(self) -> Result<(PanicHook, EyreHook), crate::eyre::Report> {
|
||||||
let theme = self.theme;
|
let theme = self.theme;
|
||||||
#[cfg(feature = "issue-url")]
|
#[cfg(feature = "issue-url")]
|
||||||
let metadata = Arc::new(self.issue_metadata);
|
let metadata = Arc::new(self.issue_metadata);
|
||||||
@ -753,9 +754,9 @@ impl HookBuilder {
|
|||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(feature = "capture-spantrace")]
|
#[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))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
7
tests/install.rs
Normal file
7
tests/install.rs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
use color_eyre::install;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn double_install_should_not_panic() {
|
||||||
|
install().unwrap();
|
||||||
|
assert!(install().is_err());
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user