{"record":{"id":"69f6614d9c8a0017","repo":"swc-project/swc","slug":"failed-to-handle-with-unknown-panic-message-69f661","errorCode":null,"errorMessage":"failed to handle with unknown panic message","messagePattern":"failed to handle with unknown panic message","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"bindings/binding_html_node/src/util.rs","lineNumber":31,"sourceCode":"            skip_filename: false,\n            ..Default::default()\n        },\n        |handler| {\n            //\n            let result =\n                std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| op(&cm, 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    .map_err(|e| e.to_pretty_error())\n}\n","sourceCodeStart":13,"sourceCodeEnd":37,"githubUrl":"https://github.com/swc-project/swc/blob/d7d74346665e36e692aa07e13d4ee3ee692ee35c/bindings/binding_html_node/src/util.rs#L13-L37","documentation":"The catch_unwind wrapper in binding_html_node/src/util.rs could not downcast the panic payload to String or &str, so it reports 'failed to handle with unknown panic message'. This happens when code panics with a non-string payload - e.g. unwrap() on a Result/Option whose error type is not &str/String (it panics with the Debug value), assert failures on integers, or panic_any with custom types. The original cause is therefore not visible in the error text.","triggerScenarios":"An .unwrap()/.expect() failure deep in swc_html_* reached through @swc/html napi APIs: the payload is the Debug-formatted error value, not a string. Typical for internal invariant violations on malformed HTML where the code panics instead of returning Err.","commonSituations":"Debugging blind: the message gives no cause; usually appears with edge-case HTML or version regressions where an internal Result was unwrapped.","solutions":["Reproduce outside the binding (swc CLI or a small Rust harness with backtraces: RUST_BACKTRACE=1) to recover the real panic payload and location","Minimize the input by bisection even without a message","Upgrade @swc/html - the fix usually lands upstream","Report to swc with the repro; unknown-payload panics are always bugs worth filing"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const out = minify(html, opts);\n} catch (e) {\n  if (String(e).includes('unknown panic message')) {\n    // payload had no message: bisect the input to find the trigger\n    failures.push({ html: file, kind: 'unknown-panic' });\n    continue;\n  }\n  throw e;\n}","preventionTips":["For unknown-payload panics, immediately capture the exact input bytes for bisection - no message will guide you","Maintain the ability to run the same input through the swc CLI with RUST_BACKTRACE=1 to recover the real panic site"],"tags":["napi","html","panic","catch-unwind","unknown-payload"],"backgroundTag":null,"analyzedSha":"d7d74346665e36e692aa07e13d4ee3ee692ee35c","analyzedAt":"2026-08-16T12:41:13.160Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}