FuelLabs/sway · error · anyhow::Error
failed to init repo at \"{}\": {}
Error message
failed to init repo at \"{}\": {} What it means
To fetch a git dependency, forc first creates a repository on disk with git2::Repository::init at the per-repo cache path. If the filesystem refuses - permission denied, read-only mount, disk full, invalid path - the git2 error is wrapped with the target directory path.
Source
Thrown at forc-pkg/src/source/git/mod.rs:449
// returning or panicking.
let _cleanup_guard = scopeguard::guard(&repo_dir, |dir| {
let _ = std::fs::remove_dir_all(dir);
});
let config = git2::Config::open_default().unwrap();
// Init auth manager
let mut auth_handler = auth::AuthHandler::default_with_config(config);
// Setup remote callbacks
let mut callback = git2::RemoteCallbacks::new();
callback.credentials(move |url, username, allowed| {
auth_handler.handle_callback(url, username, allowed)
});
// Initialise the repository.
let repo = git2::Repository::init(&repo_dir)
.map_err(|e| anyhow!("failed to init repo at \"{}\": {}", repo_dir.display(), e))?;
// Fetch the necessary references.
let (refspecs, tags) = git_ref_to_refspecs(&source.reference);
// Fetch the refspecs.
let mut fetch_opts = git2::FetchOptions::new();
fetch_opts.remote_callbacks(callback);
if tags {
fetch_opts.download_tags(git2::AutotagOption::All);
}
let repo_url_string = source.repo.to_string();
repo.remote_anonymous(&repo_url_string)?
.fetch(&refspecs, Some(&mut fetch_opts), None)
.with_context(|| {
format!(
"failed to fetch `{}`. Check your connection or run in `--offline` mode",
&repo_url_stringView on GitHub (pinned to 47e5e902fa)
Solutions
- Check write permission on the printed repo_dir and its parents; chmod/chown as needed
- Free disk space or remount the filesystem writable
- Unset or fix FORC_HOME so it points at a writable location
- Remove the half-created repo_dir and retry so init starts clean
Defensive patterns
Strategy: retry
Validate before calling
use std::{fs, path::Path};
fn cache_dir_writable(dir: &Path) -> bool {
fs::create_dir_all(dir).is_ok()
&& fs::write(dir.join(".probe"), b"").is_ok()
&& fs::remove_file(dir.join(".probe")).is_ok()
}
// before building: assert cache_dir_writable(&forc_home.join("git")); Prevention
- Ensure FORC_HOME is writable before builds in containers
- Monitor disk space on cache volumes
- Do not run forc against read-only mounts
When it happens
Trigger: The user running forc lacks write permission under the forc home git directory; the directory is on a full or read-only filesystem; FORC_HOME points somewhere unwritable.
Common situations: CI containers with restricted HOME; Docker volumes mounted read-only; sandboxes; FORC_HOME misconfigured to a path requiring root.
Related errors
- failed to write lock file: {}
- Unable to fetch pkg {:?} from {:?} in offline mode
- Cannot get commit from {}
- invalid folder name
- Cannot find local repo at checkouts dir {}
AI-assisted analysis of FuelLabs/sway@47e5e902fa (2026-08-16).
Data as JSON: /api/errors/186f3e21141761ec.
Report an issue: GitHub.