feat: improve panic handling in CI environments (#1307)

This commit is contained in:
William Woodruff 2025-11-01 19:49:56 -04:00 committed by GitHub
parent ade712d8a8
commit 96a96bcc89
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 22 additions and 1 deletions

View file

@ -804,7 +804,25 @@ fn run(app: &mut App) -> Result<ExitCode, Error> {
} }
fn main() -> ExitCode { fn main() -> ExitCode {
human_panic::setup_panic!(); // NOTE: We only use human-panic on non-CI environments.
// This is because human-panic's output gets sent to a temporary file,
// which is then typically inaccessible from an already failed
// CI job. In those cases, it's better to dump directly to stderr,
// since that'll typically be captured by console logging.
if std::env::var_os("CI").is_some() {
std::panic::set_hook(Box::new(|info| {
let trace = std::backtrace::Backtrace::force_capture();
eprintln!("FATAL: zizmor crashed. This is a bug that should be reported.");
eprintln!(
"Please report to: {repo}",
repo = env!("CARGO_PKG_REPOSITORY")
);
eprintln!("Panic information:\n{}", info);
eprintln!("Backtrace:\n{}", trace);
}));
} else {
human_panic::setup_panic!();
}
let mut app = App::parse(); let mut app = App::parse();

View file

@ -13,6 +13,9 @@ of `zizmor`.
* The [concurrency-limits] audit no longer flags explicit user concurrency * The [concurrency-limits] audit no longer flags explicit user concurrency
overrides, e.g. `cancel-in-progress: false` (#1302) overrides, e.g. `cancel-in-progress: false` (#1302)
* zizmor now detects CI environments and specializes its panic handling
accordingly, improving the quality of panic reports when running
in CI (#1307)
## 1.16.1 ## 1.16.1