{"record":{"id":"89046b40a1e4bfd8","repo":"swc-project/swc","slug":"failed-to-handle-s-89046b","errorCode":null,"errorMessage":"failed to handle: {s}","messagePattern":"failed to handle: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"bindings/binding_html_node/src/util.rs","lineNumber":27,"sourceCode":"    let cm = Lrc::new(SourceMap::new(FilePathMapping::empty()));\n    try_with_handler(\n        cm.clone(),\n        HandlerOpts {\n            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":9,"sourceCodeEnd":37,"githubUrl":"https://github.com/swc-project/swc/blob/d7d74346665e36e692aa07e13d4ee3ee692ee35c/bindings/binding_html_node/src/util.rs#L9-L37","documentation":"The napi HTML binding runs every compiler operation inside std::panic::catch_unwind (binding_html_node/src/util.rs `try_with`). When the swc HTML parser/minifier panics with a String payload, the panic is converted into this anyhow error and returned to Node as a pretty error. It means an internal panic, not a normal user-facing diagnostic: the HTML input hit a code path that unwound instead of returning an error.","triggerScenarios":"Calling minify()/parse/transform APIs of @swc/html (napi) on HTML that triggers an internal panic - malformed markup, deeply nested or pathological structures, foreign content (SVG/MathML edge cases), or a regression in the vendored swc_html_* crate version.","commonSituations":"Batch-minifying large site corpora where one unusual document panics; after upgrading @swc/html to a version with a parser regression; HTML fragments (not full documents) fed to a code path expecting full documents.","solutions":["Read the panic message in {s} - it names the internal assertion/unwrap that failed and usually points at the construct to remove","Reduce the failing HTML to a minimal repro (delete sections until the panic disappears)","Upgrade or pin @swc/html - internal panics are treated as bugs upstream and are fixed across versions","Report the minimal repro to the swc repository (bindings/binding_html_node) if it reproduces on latest","As a stopgap, skip or sanitize the offending document in your pipeline"],"exampleFix":"// before: unguarded call in a batch loop\nconst out = minify(html, opts);\n\n// after: isolate the panicking document\nlet out;\ntry {\n  out = minify(html, opts);\n} catch (e) {\n  failures.push({ file, err: String(e) });\n  continue;\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const result = minify(html, opts);\n} catch (e) {\n  // starts with 'failed to handle: ' -> internal panic, not your bug\n  if (String(e).includes('failed to handle')) {\n    logPanic(file, String(e)); // collect for an upstream report\n    return fallbackHtml; // or skip the document\n  }\n  throw e;\n}","preventionTips":["Wrap every @swc/html napi call; panics arrive as ordinary JS errors so one document never kills a batch","Pin a known-good @swc/html version in package.json instead of floating ranges","Keep a corpus of representative HTML in CI to catch panic regressions before upgrade"],"tags":["napi","html","panic","catch-unwind","minify"],"backgroundTag":null,"analyzedSha":"d7d74346665e36e692aa07e13d4ee3ee692ee35c","analyzedAt":"2026-08-16T12:41:13.160Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}