gleam-lang/gleam · error
invalid folder
Error message
invalid folder
What it means
In get_foldername, when the project root path is ".", env::current_dir() is unwrapped with .expect("invalid folder"). If the current directory cannot be read (deleted, no permission) the process panics; if the directory has no valid file_name or is not UTF-8-representable, it returns UnableToFindProjectRoot instead.
Solutions
- cd into an existing, readable directory before running the command
- Recreate the deleted directory or restart the shell
- Check permissions on the current directory
- Pass an explicit project path instead of `.` (e.g. `gleam new my_app`)
Example fix
// before (cwd deleted) $ cd /tmp/gone && gleam new . // after $ cd /tmp && gleam new my_app
Defensive patterns
Strategy: validation
Validate before calling
// check cwd before `gleam new .`
match std::env::current_dir() {
Ok(d) => println!("cwd ok: {}", d.display()),
Err(e) => eprintln!("fix cwd first: {}", e),
} Prevention
- Don't delete the directory you are cd'd into
- Pass explicit names instead of `.` when scripting
- Check permissions on the target directory
- Restart the shell if cwd state is questionable
When it happens
Trigger: Running `gleam new .` (get_valid_project_name -> get_foldername) from a working directory that no longer exists or is inaccessible to the process.
Common situations: Starting gleam from a directory removed by another process/terminal; ephemeral CI containers with vanished cwd; directories with permission changes mid-session; using a cwd path outside the UTF-8 domain on some platforms.
Related errors
- Failed to get current directory
- Directory name
- Final result error writing
- Index out of bounds
- is_gleam_path(): strip_prefix
AI-assisted analysis of gleam-lang/gleam@15b07c7830 (2026-09-14).
Data as JSON: /api/errors/9f4642a909b86d91.
Report an issue: GitHub.
Appendix: source
Thrown at compiler-cli/src/new.rs:491
decided: suggested_name,
},
None => ProjectName::Derived {
folder: initial_name,
decided: suggested_name,
},
});
}
Err(Error::InvalidProjectName {
name: initial_name,
reason: invalid_reason,
})
}
fn get_foldername(path: &str) -> Result<String, Error> {
match path {
"." => env::current_dir()
.expect("invalid folder")
.file_name()
.and_then(|x| x.to_str())
.map(ToString::to_string)
.ok_or(Error::UnableToFindProjectRoot {
path: path.to_string(),
}),
_ => Utf8Path::new(path)
.file_name()
.map(ToString::to_string)
.ok_or(Error::UnableToFindProjectRoot {
path: path.to_string(),
}),
}
}
#[derive(Debug, Clone)]
enum ProjectName {
Provided { decided: String },View on GitHub (pinned to 15b07c7830)