FuelLabs/sway · error · std::io::Error
Source file was modified, and the mapping is now out of rang
Error message
Source file was modified, and the mapping is now out of range
What it means
`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.
Source
Thrown at forc/src/cli/commands/addr2line.rs:137
if start_pos.is_none() {
if position + n > range_start {
let cbl: usize = context_buffer.iter().map(|c| c.len()).sum();
start_pos = Some((line_num, position, range_start - (position + n - cbl)));
} else if context_buffer.len() > context_lines {
let _ = context_buffer.pop_front();
}
} else if context_buffer.len() > context_lines * 2 {
break;
}
position += n;
}
let source = context_buffer.make_contiguous().join("");
let length = range_end - range_start;
let (source_start_line, _source_start_byte, offset) = start_pos.ok_or_else(|| {
io::Error::new(
io::ErrorKind::UnexpectedEof,
"Source file was modified, and the mapping is now out of range",
)
})?;
if offset + length > source.len() {
return Err(io::Error::new(
io::ErrorKind::UnexpectedEof,
"Source file was modified, and the mapping is now out of range",
));
}
Ok(ReadRange {
source,
_source_start_byte,
source_start_line,
offset,
length,View on GitHub (pinned to 47e5e902fa)
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.
Example fix
// before $ vi src/main.sw # shrink the file $ forc addr2line -s out/debug/my_pkg-source_map.json 0x3a -> UnexpectedEof // after $ forc build $ forc addr2line -s out/debug/my_pkg-source_map.json 0x3a -> snippet prints
Defensive patterns
Strategy: validation
Validate before calling
# rebuild whenever any source is newer than the source map smap=out/debug/my_pkg-source_map.json if [ "$(find src -name '*.sw' -newer "$smap" | head -n1)" ]; then forc build; fi forc addr2line -s "$smap" 0x3a
Try / catch
match res {
Err(e) if e.kind() == std::io::ErrorKind::UnexpectedEof => {
eprintln!("source changed since build; re-run forc build");
}
other => other,
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Could not get homedir
- Failed to run forc plugins
- InvalidData
- failed to parse manifest: {}.
- dependency of {:?} named {:?} is invalid: {}
AI-assisted analysis of FuelLabs/sway@47e5e902fa (2026-08-16).
Data as JSON: /api/errors/3c930412a5ecd283.
Report an issue: GitHub.