gleam-lang/gleam · error
Failed to get current directory
Error message
Failed to get current directory
What it means
In test-only helper project_paths_at_current_directory_without_toml, get_current_directory() is unwrapped with the message 'Failed to get current directory'. It fires when the process' current working directory cannot be read, usually because it was deleted or is unreadable. It is returned by/used from the build_lock test functions locking_global, locking_dev_erlang, etc.
Solutions
- cd into an existing directory before running the tests
- Recreate the deleted working directory or restart your shell/terminal
- In sandboxed/CI environments ensure the test working directory exists and is readable
- If it persists, check filesystem permissions on the directory
Example fix
// before (cwd deleted) $ rm -rf ../some-dir && cd ../some-dir && cargo test // after $ cd /path/to/gleam && cargo test -p gleam-cli build_lock
Defensive patterns
Strategy: validation
Validate before calling
// run from a directory that exists assert!(std::env::current_dir().is_ok(), "cwd missing");
Prevention
- Always run tests from an existing directory
- Restart shells after deleting directories
- Ensure CI containers seed a valid working dir
- Avoid removing the directory your shell sits in
When it happens
Trigger: Calling any of the BuildLock tests (locking_global, locking_dev_erlang, locking_prod_erlang, locking_dev_javascript, locking_prod_javascript, locking_lsp_erlang) while the shell's cwd no longer exists (deleted directory, stale container mount).
Common situations: Running `cargo test` from a directory that was removed or replaced by another process; test runners launched in ephemeral containers whose working dir vanished; sandboxed environments denying access to the cwd.
Related errors
AI-assisted analysis of gleam-lang/gleam@49f8762da5 (2026-09-14).
Data as JSON: /api/errors/d4d761f719419918.
Report an issue: GitHub.
Appendix: source
Thrown at compiler-cli/src/lib.rs:1047
fn initialise_logger() {
let enable_colours = std::env::var("GLEAM_LOG_NOCOLOUR").is_err();
tracing_subscriber::fmt()
.with_writer(std::io::stderr)
.with_env_filter(std::env::var("GLEAM_LOG").unwrap_or_else(|_| "off".into()))
.with_target(false)
.with_ansi(enable_colours)
.without_time()
.init();
}
fn find_project_paths(current_dir: Utf8PathBuf) -> Result<ProjectPaths> {
get_project_root(current_dir).map(ProjectPaths::new)
}
#[cfg(test)]
fn project_paths_at_current_directory_without_toml() -> ProjectPaths {
let current_dir = get_current_directory().expect("Failed to get current directory");
ProjectPaths::new(current_dir)
}
fn download_dependencies(paths: &ProjectPaths) -> Result<()> {
_ = dependencies::resolve_and_download(
paths,
cli::Reporter::new(),
None,
Vec::new(),
dependencies::DependencyManagerConfig {
use_manifest: dependencies::UseManifest::Yes,
check_major_versions: dependencies::CheckMajorVersions::No,
},
)?;
Ok(())
}
View on GitHub (pinned to 49f8762da5)