FuelLabs/sway · error
Could not get homedir
Error message
Could not get homedir
What it means
Source maps store dependency paths relative to ~/.forc so they resolve on any machine with the deps downloaded. SourceMapSpan::to_span rebuilds the absolute path by re-prefixing home_dir().join(".forc") when a span belongs to a dependency; this expect panics if home_dir() returns None (HOME unset / no user profile). Note the actual file is sway-core/src/source_map.rs:91 (sourcemap.rs in the report is a typo).
Source
Thrown at sway-core/src/sourcemap.rs:91
View on GitHub (pinned to 47e5e902fa)
Solutions
- Set HOME before running: `export HOME=/root` (or `docker run -e HOME=...`).
- Ensure dependencies are present under $HOME/.forc so the rebuilt prefix path is meaningful.
- As a maintainer fix, fall back to the raw relative path instead of expecting: `home_dir().map(|h| h.join(".forc")).unwrap_or_else(|| PathBuf::from(".forc"))`.
Example fix
// before (sway-core/src/source_map.rs:91)
let mut path = home_dir().expect("Could not get homedir").join(".forc");
// after
let mut path = home_dir().unwrap_or_default().join(".forc"); // or return Option and skip dep prefixing Defensive patterns
Strategy: validation
Validate before calling
# ensure a home directory exists before any debug/addr2line session
if [ -z "${HOME:-}" ]; then export HOME="$PWD/.home"; mkdir -p "$HOME"; fi
forc addr2line -s out/debug/my_pkg-source_map.json 0x3a Prevention
- Set HOME in containers/CI even when the build itself does not need it — debug tooling does.
- Pre-download dependencies (`forc build`) so dependency paths under $HOME/.forc resolve.
- When embedding source maps in other tools, avoid SourceMapSpan::to_span in HOME-less processes.
When it happens
Trigger: Inverse source mapping (SourceMap::addr_to_span, used by forc addr2line / debug tooling) resolving a pc that lands inside a dependency source while HOME is unset — container/CI builds or services without a home directory.
Common situations: Running `forc addr2line` in CI containers without HOME; debugging a revert whose mapped location is in a dependency (e.g. sway-lib-std under ~/.forc) rather than user code.
Related errors
- Source file was modified, and the mapping is now out of rang
- unable to find the user home directory
- InvalidData
- Failed to execute ps command
- Failed to execute tasklist command
AI-assisted analysis of FuelLabs/sway@47e5e902fa (2026-08-16).
Data as JSON: /api/errors/e8edfbd97af318f8.
Report an issue: GitHub.