Skip to content

Commit

Permalink
fix: panic hook panic (foundry-rs#3182)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored and iFrostizz committed Nov 9, 2022
1 parent 048aee0 commit 62965bc
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion cli/src/handler.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use eyre::EyreHandler;
use std::error::Error;
use tracing::error;
use yansi::Paint;

/// A custom context type for Foundry specific error reporting via `eyre`
Expand Down Expand Up @@ -47,6 +48,7 @@ impl EyreHandler for Handler {
/// verbose debug-centric handler is installed.
///
/// Panics are always caught by the more debug-centric handler.
#[cfg_attr(windows, inline(never))]
pub fn install() -> eyre::Result<()> {
let debug_enabled = std::env::var("FOUNDRY_DEBUG").is_ok();

Expand All @@ -59,7 +61,14 @@ pub fn install() -> eyre::Result<()> {
)
.into_hooks();
panic_hook.install();
eyre::set_hook(Box::new(move |_| Box::new(Handler)))?;
// see <https://github.com/foundry-rs/foundry/issues/3050>
if cfg!(windows) {
if let Err(err) = eyre::set_hook(Box::new(move |_| Box::new(Handler))) {
error!(?err, "failed to install panic hook");
}
} else {
eyre::set_hook(Box::new(move |_| Box::new(Handler)))?;
}
}

Ok(())
Expand Down

0 comments on commit 62965bc

Please sign in to comment.