Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: panic hook panic #3182

Merged
merged 1 commit into from
Sep 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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