{"record":{"id":"94528e135893c33e","repo":"swc-project/swc","slug":"failed-to-handle-s-94528e","errorCode":null,"errorMessage":"failed to handle: {s}","messagePattern":"failed to handle: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"bindings/binding_html_wasm/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_wasm/src/util.rs#L9-L37","documentation":"The wasm (browser) HTML binding mirrors binding_html_node's util.rs: every operation runs inside catch_unwind inside try_with_handler, and a panic whose payload is a String is converted to 'failed to handle: {s}' and returned through to_pretty_error to JS. It marks an internal panic in the wasm-compiled swc HTML compiler, not a user diagnostic.","triggerScenarios":"Calling the wasm HTML parse/minify APIs (e.g. @swc/wasm-based html bindings) in the browser/bundler on markup that panics the HTML compiler: malformed nesting, pathological attribute structures, or a swc_html_* regression in the vendored version.","commonSituations":"In-browser HTML minification of user-uploaded content; wasm build pipeline where one input kills the whole worker; version skew between the wasm package and expected HTML grammar.","solutions":["Capture {s} from the thrown error - it names the internal panic - and minimize the document","Upgrade the wasm html binding package; internal panics are fixed upstream","Run the same input through the napi binding or swc CLI to confirm it is input-dependent, not wasm-specific","Wrap calls so a panic rejects a promise instead of crashing the page (wasm panics otherwise trap the module)"],"exampleFix":"// before\nimport { minify } from '...wasm';\nconst out = minify(html, opts);\n\n// after: keep the module usable after a panic-derived error\nlet out;\ntry {\n  out = minify(html, opts);\n} catch (e) {\n  reportBadInput(file, String(e));\n  continue;\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"let out;\ntry {\n  out = minify(html, opts);\n} catch (e) {\n  if (String(e).startsWith('failed to handle')) {\n    reportAndSkip(file, e); // internal panic: keep the worker alive\n  } else throw e;\n}","preventionTips":["Run wasm HTML compilation inside a Web Worker so panic-derived errors never trap the main thread","Version-pin the wasm html binding and smoke-test your HTML corpus on every upgrade"],"tags":["wasm","html","panic","catch-unwind","minify","browser"],"backgroundTag":null,"analyzedSha":"d7d74346665e36e692aa07e13d4ee3ee692ee35c","analyzedAt":"2026-08-16T12:41:13.160Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}