{"record":{"id":"3c930412a5ecd283","repo":"FuelLabs/sway","slug":"source-file-was-modified-and-the-mapping-is-now-o","errorCode":null,"errorMessage":"Source file was modified, and the mapping is now out of range","messagePattern":"Source file was modified, and the mapping is now out of range","errorType":"console","errorClass":"std::io::Error","httpStatus":null,"severity":"error","filePath":"forc/src/cli/commands/addr2line.rs","lineNumber":137,"sourceCode":"        if start_pos.is_none() {\n            if position + n > range_start {\n                let cbl: usize = context_buffer.iter().map(|c| c.len()).sum();\n                start_pos = Some((line_num, position, range_start - (position + n - cbl)));\n            } else if context_buffer.len() > context_lines {\n                let _ = context_buffer.pop_front();\n            }\n        } else if context_buffer.len() > context_lines * 2 {\n            break;\n        }\n\n        position += n;\n    }\n\n    let source = context_buffer.make_contiguous().join(\"\");\n    let length = range_end - range_start;\n\n    let (source_start_line, _source_start_byte, offset) = start_pos.ok_or_else(|| {\n        io::Error::new(\n            io::ErrorKind::UnexpectedEof,\n            \"Source file was modified, and the mapping is now out of range\",\n        )\n    })?;\n\n    if offset + length > source.len() {\n        return Err(io::Error::new(\n            io::ErrorKind::UnexpectedEof,\n            \"Source file was modified, and the mapping is now out of range\",\n        ));\n    }\n\n    Ok(ReadRange {\n        source,\n        _source_start_byte,\n        source_start_line,\n        offset,\n        length,","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/FuelLabs/sway/blob/47e5e902faa42baf652dd6a0c88cd23390c1a614/forc/src/cli/commands/addr2line.rs#L119-L155","documentation":"`forc addr2line` reconstructs a source snippet from a source map by reading the .sw file and locating the recorded LineCol range. start_pos remains None when the read loop reaches EOF without ever reaching range_start — i.e. the file now has fewer lines/bytes than when the source map was recorded. This io::Error (UnexpectedEof) reports that the source file was modified after the build, invalidating the line/column mapping.","triggerScenarios":"Editing or shortening the .sw source between `forc build` and `forc addr2line`; using a source map built from a different commit whose file was longer; line-ending or formatting changes that shift the recorded start position past the current end of file.","commonSituations":"Iterating on a reverting test: edit source, forget to rebuild, run addr2line on the stale binary and stale source map; CI caching old artifacts while sources advance; checking out a newer commit but reusing out/debug/*-source_map.json.","solutions":["Rebuild so the source map matches the sources: `forc build`, then re-run the addr2line command.","Check out the exact commit the artifact was built from before running addr2line.","Restore the file via `git status`/`git stash` so its content matches the build, then retry."],"exampleFix":"// before\n$ vi src/main.sw        # shrink the file\n$ forc addr2line -s out/debug/my_pkg-source_map.json 0x3a  -> UnexpectedEof\n// after\n$ forc build\n$ forc addr2line -s out/debug/my_pkg-source_map.json 0x3a  -> snippet prints","handlingStrategy":"validation","validationCode":"# rebuild whenever any source is newer than the source map\nsmap=out/debug/my_pkg-source_map.json\nif [ \"$(find src -name '*.sw' -newer \"$smap\" | head -n1)\" ]; then forc build; fi\nforc addr2line -s \"$smap\" 0x3a","typeGuard":null,"tryCatchPattern":"match res {\n    Err(e) if e.kind() == std::io::ErrorKind::UnexpectedEof => {\n        eprintln!(\"source changed since build; re-run forc build\");\n    }\n    other => other,\n}","preventionTips":["Treat `forc build` as a prerequisite of every addr2line invocation; chain them in one command.","Keep binary and *-source_map.json from the same build run; never mix CI artifacts across commits.","Avoid editing sources while a debugging session holds an old source map."],"tags":["rust","sway","forc","addr2line","source-map","stale-artifact","eof"],"backgroundTag":null,"analyzedSha":"47e5e902faa42baf652dd6a0c88cd23390c1a614","analyzedAt":"2026-08-16T07:57:45.555Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}