{"record":{"id":"6c5b935555e3e76e","repo":"swc-project/swc","slug":"failed-to-handle-s-6c5b93","errorCode":null,"errorMessage":"failed to handle: {s}","messagePattern":"failed to handle: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"bindings/binding_minifier_node/src/util.rs","lineNumber":48,"sourceCode":"    GLOBALS\n        .set(&Default::default(), || {\n            try_with_handler(\n                cm,\n                swc_error_reporters::handler::HandlerOpts {\n                    skip_filename,\n                    ..Default::default()\n                },\n                |handler| {\n                    //\n                    let result = catch_unwind(AssertUnwindSafe(|| op(handler)));\n\n                    let p = match result {\n                        Ok(v) => return v,\n                        Err(v) => v,\n                    };\n\n                    if let Some(s) = p.downcast_ref::<String>() {\n                        Err(anyhow!(\"failed to handle: {s}\"))\n                    } else if let Some(s) = p.downcast_ref::<&str>() {\n                        Err(anyhow!(\"failed to handle: {s}\"))\n                    } else {\n                        Err(anyhow!(\"failed to handle with unknown panic message\"))\n                    }\n                },\n            )\n        })\n        .map_err(|e| e.to_pretty_error())\n}\n\n// This was originally under swc_nodejs_common, but this is not a public\n// interface for the custom binary - they should choose own trace initialization\n// instead. Will keep as hidden for now until there's proper usecase.\n\n/// Deprecated no-op kept for compatibility with existing binding entrypoints.\npub fn init_default_trace_subscriber() {}\n","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/swc-project/swc/blob/d7d74346665e36e692aa07e13d4ee3ee692ee35c/bindings/binding_minifier_node/src/util.rs#L30-L66","documentation":"The Node minifier binding (bindings/binding_minifier_node/src/util.rs `try_with`) wraps each operation in catch_unwind under GLOBALS; a panic with a String payload becomes 'failed to handle: {s}' and is returned as a pretty error. This is the napi @swc/minifier surface: the JS minifier (compressor/mangler/printer) panicked instead of returning Err.","triggerScenarios":"Calling minify() from @swc/minifier (napi) on JavaScript whose compression/mangling path panics - known edge cases in swc_ecma_minifier for specific versions (inliner, mangler, or DCE invariants on unusual AST shapes produced by modern syntax).","commonSituations":"CI minification of large bundles failing on one chunk after a dependency or @swc/minifier upgrade; production builds with compress/mangle enabled hitting a version-specific panic; usually resolves by pinning or bumping the package.","solutions":["Read {s} - it identifies the panicking assertion inside the minifier","Toggle minify options to isolate the pass (compress: false, then mangle: false, then individual compress toggles) and minimize the JS repro","Upgrade (or if newly broken, pin/roll back) @swc/minifier - panics are fixed frequently","Report the reproducible case to the swc repo with the option set and input"],"exampleFix":"// before\nconst out = minify(code, { compress: true, mangle: true });\n\n// after: bisect which pass panics\nconst out = minify(code, { compress: false, mangle: true }); // still panics? -> mangler\nconst out2 = minify(code, { compress: true, mangle: false }); // -> compressor","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const out = minify(code, minifyOpts);\n} catch (e) {\n  const msg = String(e);\n  if (msg.startsWith('failed to handle:')) {\n    // internal minifier panic: capture code + opts, fall back to unminified or mangle-only\n    return { code, panic: msg };\n  }\n  throw e;\n}","preventionTips":["Wrap every @swc/minifier call in build scripts; a panic must not abort CI without capturing the chunk","Pin the minifier version; upgrade deliberately and run your bundle corpus as a regression test","Record the option set alongside panics - compress/mangle toggles are the fastest way to isolate the buggy pass"],"tags":["napi","minifier","panic","catch-unwind","compress","mangle"],"backgroundTag":null,"analyzedSha":"d7d74346665e36e692aa07e13d4ee3ee692ee35c","analyzedAt":"2026-08-16T12:41:13.160Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}