{"record":{"id":"3d3b41b57b2d1324","repo":"swc-project/swc","slug":"failed-to-handle-s","errorCode":null,"errorMessage":"failed to handle: {s}","messagePattern":"failed to handle: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"bindings/binding_core_node/src/util.rs","lineNumber":55,"sourceCode":"    GLOBALS\n        .set(&Default::default(), || {\n            try_with_handler(\n                cm,\n                swc_core::base::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":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/bindings/binding_core_node/src/util.rs#L37-L73","documentation":"binding_core_node's try_with_handler runs the swc operation inside catch_unwind so a Rust panic inside the native binding does not abort the Node.js process. If the panic payload is a String (panic!(\"...{}\", x) format), it is downcast and converted into an anyhow error 'failed to handle: <payload>'. The message you see is therefore the original panic text; the underlying cause is a bug or unrecoverable condition inside swc's transform pipeline.","triggerScenarios":"Any swc transform/parse/minify call through @swc/core (native) whose internal code panics with a formatted String message — e.g. an unimplemented syntax path, an invariant violation on unusual AST shapes, or explicit panic! in the invoked code path.","commonSituations":"Hitting an swc internal bug on exotic input (decorator edge cases, unusual Unicode, deeply nested ASTs); version regressions after upgrading @swc/core; panics surfacing from user plugins or visitors that panic! with format strings.","solutions":["Treat the appended payload as the real error message and search swc's issue tracker for it; if absent, minimize the input and report a bug","Upgrade or downgrade @swc/core to a version where the panic path is fixed (many panics are patched quickly)","Wrap the JS call and capture the error so build tooling (webpack/vite/jest) reports it instead of crashing the pipeline","If the panic comes from your own visitor/plugin code, replace panic!/unwrap with proper error returns"],"exampleFix":"// before (js caller)\nconst out = transformSync(src, opts); // panics inside native code\n\n// after: contain the failure and surface it\ntry {\n  const out = transformSync(src, opts);\n} catch (e) {\n  // e.message starts with 'failed to handle: ' + original panic text\n  throw new Error(`swc transform failed: ${e.message}`);\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const out = transformSync(src, opts);\n} catch (e) {\n  const m = /failed to handle: ([\\s\\S]*)$/.exec(e.message);\n  const panicText = m ? m[1] : e.message;\n  throw new Error(`swc internal failure (${panicText}); check swc issue tracker`);\n}","preventionTips":["Wrap every swc native call in try/catch so panics surface as build errors, not crashes","Pin @swc/core versions and test upgrades in CI before rolling out","Minify-then-diff in CI to catch panics on real-world inputs early"],"tags":["panic","native-binding","node-binding","swc-core","catch-unwind"],"backgroundTag":"caught-panic-as-error","analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","contentChangedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}