{"record":{"id":"76c048780181cef0","repo":"swc-project/swc","slug":"invalid-vlq-segment-size-expected-4-or-5-got","errorCode":null,"errorMessage":"invalid vlq segment size; expected 4 or 5, got {}","messagePattern":"invalid vlq segment size; expected 4 or 5, got (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_config/src/source_map.rs","lineNumber":76,"sourceCode":"                    }\n\n                    dst_col = 0;\n\n                    for segment in line.split(',') {\n                        if segment.is_empty() {\n                            continue;\n                        }\n\n                        nums.clear();\n                        nums = parse_vlq_segment(segment)?;\n                        dst_col = (i64::from(dst_col) + nums[0]) as u32;\n\n                        let mut src = !0;\n                        let mut name = !0;\n\n                        if nums.len() > 1 {\n                            if nums.len() != 4 && nums.len() != 5 {\n                                bail!(\n                                    \"invalid vlq segment size; expected 4 or 5, got {}\",\n                                    nums.len()\n                                );\n                            }\n                            src_id = (i64::from(src_id) + nums[1]) as u32;\n                            if src_id >= sources.len() as u32 {\n                                bail!(\"invalid source reference: {src_id}\");\n                            }\n\n                            src = src_id;\n                            src_line = (i64::from(src_line) + nums[2]) as u32;\n                            src_col = (i64::from(src_col) + nums[3]) as u32;\n\n                            if nums.len() > 4 {\n                                name_id = (i64::from(name_id) + nums[4]) as u32;\n                                if name_id >= names.len() as u32 {\n                                    bail!(\"invalid name reference: {name_id}\");\n                                }","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_config/src/source_map.rs#L58-L94","documentation":"SourceMapContent::Parsed::to_sourcemap() in swc_config decodes the `mappings` field of a source map passed in parsed-object form (e.g. swc's `inputSourceMap` config). Each comma-separated VLQ segment must contain either 1 field (generated column delta only) or exactly 4/5 fields (column, source index, source line, source column, optional name index). When a segment decodes to 2, 3, or 6+ numbers the mapping data is malformed and decoding aborts with this bail.","triggerScenarios":"Calling a swc transform API with `inputSourceMap` supplied as an object whose `mappings` string contains a segment with an illegal field count, e.g. 'AAAA,AA' or a segment where fields were dropped or duplicated during hand-editing/truncation of the JSON.","commonSituations":"Round-tripping a source map through a custom tool that rewrites mappings; consuming a source map from a bundler/minifier that emits nonstandard segments; copying only part of the mappings string when constructing the config; stale/corrupted source maps cached on disk from a previous build.","solutions":["Feed the source map as a raw JSON string (SourceMapContent::Json) so swc_sourcemap's full parser handles it, and fix the mappings if that parser also rejects them","Validate the source map with a standard tool (e.g. the `source-map` npm library or `sourcemaps` CLI) before passing it to swc to find the exact corrupt segment","Regenerate the source map from the tool that originally produced the minified/bundled output instead of reusing a mutated copy","If the input source map is optional for your pipeline, omit it and let swc generate fresh mappings from sourcesContent"],"exampleFix":"// before (corrupt segment: 'AAAA,AA,BBBB')\nlet cfg = CompilerInput {\n    input_source_map: Some(InputSourceMap::SourceMapFile(SourceMapFile {\n        src: SourceMapContent::Parsed { /* mappings with bad segment */ .. },\n        ..\n    })),\n    ..Default::default()\n};\n\n// after: pass the original JSON string so the standard parser validates it\nlet cfg = CompilerInput {\n    input_source_map: Some(InputSourceMap::SourceMapFile(SourceMapFile {\n        src: SourceMapContent::Json(original_json.to_string()),\n        ..\n    })),\n    ..Default::default()\n};","handlingStrategy":"validation","validationCode":"// Validate segment field counts before handing the map to swc (Node side)\nfunction mappingsLookSane(mappings) {\n  for (const line of mappings.split(';')) {\n    for (const seg of line.split(',')) {\n      if (seg === '') continue;\n      // count VLQ fields by sign-bit terminators\n      let fields = 0;\n      for (const ch of seg) {\n        const v = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.indexOf(ch);\n        if (v < 0) return false;\n        if ((v & 32) === 0) fields += 1; // continuation bit clear -> field end\n      }\n      if (fields !== 1 && fields !== 4 && fields !== 5) return false;\n    }\n  }\n  return true;\n}\nif (!mappingsLookSane(map.mappings)) throw new Error('corrupt input source map');","typeGuard":null,"tryCatchPattern":"try { await transform(src, { inputSourceMap: map }) } catch (e) { if (/invalid vlq segment size/.test(e.message)) { /* drop bad map, retry without it */ } else throw e; }","preventionTips":["Never hand-edit `mappings`; regenerate source maps from their producer instead","Round-trip incoming source maps through a standard parser (source-map npm) as a validation gate in CI","Prefer passing inputSourceMap as the original JSON string rather than a re-assembled object"],"tags":["sourcemap","vlq","input-sourcemap","swc-config","malformed-input"],"backgroundTag":"malformed-sourcemap-mappings","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"}