{"record":{"id":"7881f03101b1e275","repo":"swc-project/swc","slug":"invalid-utf8","errorCode":null,"errorMessage":"invalid utf8","messagePattern":"invalid utf8","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_sourcemap/src/encoder.rs","lineNumber":102,"sourceCode":"                encode_rmi(&mut buf, &rmi_data);\n                rmi_data.clear();\n            }\n\n            buf.push(b';');\n            prev_line += 1;\n            had_rmi = false;\n            idx_of_first_in_line = idx;\n        }\n    }\n    if empty {\n        return None;\n    }\n\n    if had_rmi {\n        encode_rmi(&mut buf, &rmi_data);\n    }\n\n    Some(String::from_utf8(buf).expect(\"invalid utf8\"))\n}\n\nfn serialize_mappings(sm: &SourceMap) -> String {\n    let mut rv = String::new();\n    // dst == minified == generated\n    let mut prev_dst_line = 0;\n    let mut prev_dst_col = 0;\n    let mut prev_src_line = 0;\n    let mut prev_src_col = 0;\n    let mut prev_name_id = 0;\n    let mut prev_src_id = 0;\n\n    for (idx, token) in sm.tokens().enumerate() {\n        if token.get_dst_line() != prev_dst_line {\n            prev_dst_col = 0;\n            while token.get_dst_line() != prev_dst_line {\n                rv.push(';');\n                prev_dst_line += 1;","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_sourcemap/src/encoder.rs#L84-L120","documentation":"serialize_range_mappings in swc_sourcemap builds the rangeMappings field as a Vec<u8> of base64 characters (from encode_rmi, values A-Za-z0-9+/) plus ';' separators, then asserts the buffer is valid UTF-8. Since every byte pushed is ASCII by construction, this expect indicates an internal invariant violation or a bug in swc_sourcemap's range-mapping encoder, not bad user data.","triggerScenarios":"Encoding a SourceMap that contains range tokens (is_range set on tokens) - e.g. maps produced by tools that attach range mapping info - triggers serialize_range_mappings; the panic itself only fires if the encoder emitted a non-ASCII byte.","commonSituations":"Practically limited to swc_sourcemap regressions or corrupted in-memory Token state after map manipulation; users see it as a crash while generating a sourcemap for output containing range mappings.","solutions":["Pin the swc_core/swc version to the last known-good release for your pipeline.","Strip range-mapping info before re-encoding (rebuild the map through SourceMapBuilder without is_range) if you depend on third-party range tokens.","Report an upstream issue at swc-project/swc with the minimal SourceMap that reproduces it."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Internal invariant assertion: contain it so map generation does not\n// abort the pipeline, then fall back to a map without rangeMappings.\nlet encoded = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {\n    sm.to_writer(&mut out)\n}));\nif encoded.is_err() {\n    tracing::error!(\"rangeMappings encoding panicked; emitting map without range info\");\n    drop_range_tokens(&mut sm);\n    sm.to_writer(&mut out)?;\n}","preventionTips":["Pin swc_core/swc to a release validated by your sourcemap tests.","Round-trip test (encode-decode-encode) maps that contain range tokens in CI.","Report the reproducer upstream; this path is ASCII-only by construction."],"tags":["sourcemap","utf8","encoding","panic"],"backgroundTag":"utf8-encoding-failed","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"}