swc-project/swc · error · anyhow::Error
failed to handle with unknown panic message
Error message
failed to handle with unknown panic message
What it means
The minifier napi binding's catch_unwind could not downcast the panic payload to String or &str, so it returns 'failed to handle with unknown panic message'. The panic came from an unwrap()/expect() on a typed error; its Debug payload is discarded, so the message carries no cause - only the pretty handler output around it may help.
Source
Thrown at bindings/binding_minifier_node/src/util.rs:52
swc_error_reporters::handler::HandlerOpts {
skip_filename,
..Default::default()
},
|handler| {
//
let result = catch_unwind(AssertUnwindSafe(|| op(handler)));
let p = match result {
Ok(v) => return v,
Err(v) => v,
};
if let Some(s) = p.downcast_ref::<String>() {
Err(anyhow!("failed to handle: {s}"))
} else if let Some(s) = p.downcast_ref::<&str>() {
Err(anyhow!("failed to handle: {s}"))
} else {
Err(anyhow!("failed to handle with unknown panic message"))
}
},
)
})
.map_err(|e| e.to_pretty_error())
}
// This was originally under swc_nodejs_common, but this is not a public
// interface for the custom binary - they should choose own trace initialization
// instead. Will keep as hidden for now until there's proper usecase.
/// Deprecated no-op kept for compatibility with existing binding entrypoints.
pub fn init_default_trace_subscriber() {}
View on GitHub (pinned to d7d7434666)
Solutions
- Re-run the failing input with the swc CLI or a Rust harness with RUST_BACKTRACE=1 to recover the real panic and location
- Bisect the JS input and the minify options without a message to guide you
- Pin a known-good @swc/minifier version while reporting the case upstream
- Include options + input in the upstream issue; unknown-payload panics always warrant a fix
Defensive patterns
Strategy: try-catch
Try / catch
try {
const out = minify(code, opts);
} catch (e) {
if (String(e).includes('unknown panic message')) {
saveRepro(code, opts, null); // no payload info
return { code }; // ship unminified rather than fail the release
}
throw e;
} Prevention
- For unknown-payload panics, first reproduce with RUST_BACKTRACE=1 via the swc CLI to get a stack
- Bisect options first (compress/mangle off), then bisect the code - no message will help you
When it happens
Trigger: Internal .unwrap()/.expect() failures in the JS compressor/mangler triggered by specific inputs through @swc/minifier; payload is the error's Debug value (e.g. a Box<Error> or struct), not a string.
Common situations: Blind failures in build pipelines; most common right after version changes when an internal invariant regressed.
Related errors
- failed to handle with unknown panic message
- failed to handle: {s}
- failed to handle: {s}
- failed to handle with unknown panic message
- failed to handle: {s}
AI-assisted analysis of swc-project/swc@d7d7434666 (2026-08-16).
Data as JSON: /api/errors/15a3eb0d79a92584.
Report an issue: GitHub.