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

  1. Set HOME before running: `export HOME=/root` (or `docker run -e HOME=...`).
  2. Ensure dependencies are present under $HOME/.forc so the rebuilt prefix path is meaningful.
  3. 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

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


AI-assisted analysis of FuelLabs/sway@47e5e902fa (2026-08-16). Data as JSON: /api/errors/e8edfbd97af318f8. Report an issue: GitHub.