{"record":{"id":"ef4c370475b8246a","repo":"swc-project/swc","slug":"it-should-not-fail-without-emitting-errors-to-hand","errorCode":null,"errorMessage":"it should not fail without emitting errors to handler","messagePattern":"it should not fail without emitting errors to handler","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"bindings/binding_nodejs_support_wasm/src/lib.rs","lineNumber":147,"sourceCode":"{\n    let wr = JsonErrorWriter {\n        errors: Default::default(),\n        reporter: None,\n        cm,\n    };\n    let emitter: Box<dyn Emitter> = Box::new(wr.clone());\n\n    let handler = Handler::with_emitter(true, false, emitter);\n\n    let ret = HANDLER.set(&handler, || op(&handler));\n\n    if handler.has_errors() {\n        let mut lock = wr.errors.lock().unwrap();\n        let error = take(&mut *lock);\n\n        Err(error)\n    } else {\n        Ok(ret.expect(\"it should not fail without emitting errors to handler\"))\n    }\n}\n\nimpl Emitter for JsonErrorWriter {\n    fn emit(&mut self, db: &mut DiagnosticBuilder) {\n        let d = &**db;\n\n        let snippet = d.span.primary_span().and_then(|span| {\n            let mut snippet = String::new();\n            let reporter = self.reporter.get_or_insert_with(json_reporter);\n            match reporter.render_report(\n                &mut snippet,\n                &Snippet {\n                    source_code: &to_pretty_source_code(&self.cm, true),\n                    span,\n                },\n            ) {\n                Ok(()) => Some(snippet),","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/bindings/binding_nodejs_support_wasm/src/lib.rs#L129-L165","documentation":"Defensive expect in try_with_json_handler: HANDLER.set returned Err even though handler.has_errors() was false, violating the invariant that operations either succeed or report diagnostics to the handler. Reaching it means an error escaped without being emitted — an internal bug, not bad user input.","triggerScenarios":"Thrown at bindings/binding_nodejs_support_wasm/src/lib.rs:147 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Report as an swc internal bug with the input that triggered it","Audit the wrapped op for error paths that return Err without emitting to the Handler"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","contentChangedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}