{"record":{"id":"7152b0f31f3a0432","repo":"swc-project/swc","slug":"invalid-utf8-character-detected","errorCode":null,"errorMessage":"invalid utf8 character detected","messagePattern":"invalid utf8 character detected","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_compiler_base/src/lib.rs","lineNumber":238,"sourceCode":"            w.preamble(preamble).unwrap();\n            let mut wr = Box::new(w) as Box<dyn WriteJs>;\n\n            if codegen_config.minify {\n                wr = Box::new(swc_ecma_codegen::text_writer::omit_trailing_semi(wr));\n            }\n\n            let mut emitter = Emitter {\n                cfg: codegen_config,\n                comments,\n                cm: cm.clone(),\n                wr,\n            };\n\n            node.emit_with(&mut emitter)\n                .context(\"failed to emit module\")?;\n        }\n        // Invalid utf8 is valid in javascript world.\n        String::from_utf8(buf).expect(\"invalid utf8 character detected\")\n    };\n\n    if cfg!(debug_assertions)\n        && !src_map_buf.is_empty()\n        && src_map_buf.iter().all(|(bp, _)| bp.is_dummy())\n        && src.lines().count() >= 3\n        && option_env!(\"SWC_DEBUG\") == Some(\"1\")\n    {\n        panic!(\"The module contains only dummy spans\\n{src}\");\n    }\n\n    let additional_scope_names = scope_buf\n        .as_deref()\n        .map(source_map_scopes::collect_additional_names)\n        .unwrap_or_default();\n\n    let mut map = if source_map.enabled() {\n        Some(cm.build_source_map(","sourceCodeStart":220,"sourceCodeEnd":256,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_compiler_base/src/lib.rs#L220-L256","documentation":"In swc_compiler_base's print function, the emitted JavaScript output buffer contained invalid UTF-8 when converted with String::from_utf8 after printing. JavaScript strings are UTF-16, so codegen can produce byte sequences (e.g. from lone surrogates in string literals) that are valid JS source but not valid UTF-8; this fires when the host demands a Rust String and such bytes are present.","triggerScenarios":"Thrown at crates/swc_compiler_base/src/lib.rs:238 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Avoid lone surrogates (\\uD800-\\uDFFF unpaired) in source string literals","Sanitize or replace unpaired surrogates in input data before compilation","If the output crosses a UTF-16 boundary (e.g. JS host), use lossy conversion or byte-level output APIs"],"exampleFix":null,"handlingStrategy":"validation","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"}