{"record":{"id":"ea9a4b3ae5b858eb","repo":"FuelLabs/sway","slug":"invalid-source-map-json","errorCode":null,"errorMessage":"{:?}: invalid source map json: {}","messagePattern":"(.+?): invalid source map json: (.+?)","errorType":"console","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"forc/src/cli/commands/addr2line.rs","lineNumber":37,"sourceCode":"    #[clap(short = 'S', long, default_value = \".\")]\n    pub search_dir: PathBuf,\n    /// Source file mapping in JSON format\n    #[clap(short = 'g', long)]\n    pub sourcemap_path: PathBuf,\n    /// How many lines of context to show\n    #[clap(short, long, default_value = \"2\")]\n    pub context: usize,\n    /// Opcode index\n    #[clap(short = 'i', long)]\n    pub opcode_index: usize,\n}\n\npub(crate) fn exec(command: Command) -> ForcResult<()> {\n    let contents = fs::read(&command.sourcemap_path)\n        .map_err(|err| anyhow!(\"{:?}: could not read: {:?}\", command.sourcemap_path, err))?;\n\n    let sm: SourceMap = serde_json::from_slice(&contents).map_err(|err| {\n        anyhow!(\n            \"{:?}: invalid source map json: {}\",\n            command.sourcemap_path,\n            err\n        )\n    })?;\n\n    if let Some((mut path, range)) = sm.addr_to_span(command.opcode_index) {\n        if path.is_relative() {\n            path = command.search_dir.join(path);\n        }\n\n        let rr = read_range(&path, range, command.context)\n            .map_err(|err| anyhow!(\"{:?}: could not read: {:?}\", path, err))?;\n\n        let path_str = format!(\"{path:?}\");\n        let snippet = Snippet {\n            title: None,\n            footer: vec![],","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/FuelLabs/sway/blob/47e5e902faa42baf652dd6a0c88cd23390c1a614/forc/src/cli/commands/addr2line.rs#L19-L55","documentation":"After reading the sourcemap file bytes, forc addr2line deserializes them with serde_json::from_slice::<SourceMap>; failure produces \"<path>: invalid source map json: <serde error>\" including the serde message (line/column of the parse failure). The file was readable but is not valid JSON shaped like a SourceMap.","triggerScenarios":"Passing a non-sourcemap file to `forc addr2line -g` — e.g. the ABI json, the raw .bin bytecode, or a truncated/edited sourcemap — so serde_json errors at syntax or at a type mismatch within the SourceMap structure.","commonSituations":"Mixing up the several json artifacts forc produces (ABI vs sourcemap), sourcemaps produced by an incompatible forc version with a different schema, or files mangled by text-mode processing (line-ending/CRLF rewrites, leading BOM).","solutions":["Point -g at the file produced by `forc build -g` for the same binary you are debugging","Validate the file parses as JSON and contains SourceMap fields (the serde message names the offending position/field)","Regenerate the sourcemap with the same forc version that built the bytecode"],"exampleFix":"# before\nforc addr2line -g out/debug/my_pkg-abi.json -i 42\n\n# after\nforc addr2line -g out/debug/my_pkg.bin.json -i 42","handlingStrategy":"validation","validationCode":"// Cheap pre-flight: the file must be JSON before handing it to addr2line.\nlet raw = std::fs::read(&sm_path)?;\nserde_json::from_slice::<serde_json::Value>(&raw)\n    .map_err(|e| anyhow::anyhow!(\"{} is not valid JSON ({e}) — is this the sourcemap from `forc build -g`?\", sm_path.display()))?;","typeGuard":"fn looks_like_sourcemap(v: &serde_json::Value) -> bool {\n    v.get(\"program\").is_some() || v.get(\"asm\").is_some() || v.is_array()\n}","tryCatchPattern":"match serde_json::from_slice::<SourceMap>(&contents) {\n    Ok(sm) => sm,\n    Err(e) => anyhow::bail!(\"{e}: {} — likely the wrong artifact; use the .bin.json emitted by `forc build -g`\", path.display()),\n}","preventionTips":["Don't confuse the ABI json with the sourcemap json; both live under out/ but only the -g-emitted file maps opcodes","Regenerate sourcemaps with the same forc version that produced the bytecode"],"tags":["forc","addr2line","sourcemap","json-parse"],"backgroundTag":null,"analyzedSha":"47e5e902faa42baf652dd6a0c88cd23390c1a614","analyzedAt":"2026-08-16T07:57:45.555Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}