{"record":{"id":"9f4642a909b86d91","repo":"gleam-lang/gleam","slug":"invalid-folder","errorCode":null,"errorMessage":"invalid folder","messagePattern":"invalid folder","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler-cli/src/new.rs","lineNumber":491,"sourceCode":"                decided: suggested_name,\n            },\n            None => ProjectName::Derived {\n                folder: initial_name,\n                decided: suggested_name,\n            },\n        });\n    }\n\n    Err(Error::InvalidProjectName {\n        name: initial_name,\n        reason: invalid_reason,\n    })\n}\n\nfn get_foldername(path: &str) -> Result<String, Error> {\n    match path {\n        \".\" => env::current_dir()\n            .expect(\"invalid folder\")\n            .file_name()\n            .and_then(|x| x.to_str())\n            .map(ToString::to_string)\n            .ok_or(Error::UnableToFindProjectRoot {\n                path: path.to_string(),\n            }),\n        _ => Utf8Path::new(path)\n            .file_name()\n            .map(ToString::to_string)\n            .ok_or(Error::UnableToFindProjectRoot {\n                path: path.to_string(),\n            }),\n    }\n}\n\n#[derive(Debug, Clone)]\nenum ProjectName {\n    Provided { decided: String },","sourceCodeStart":473,"sourceCodeEnd":509,"githubUrl":"https://github.com/gleam-lang/gleam/blob/7e623aa83da3776faee50ca4ab9a6c40124acd95/compiler-cli/src/new.rs#L473-L509","documentation":"get_foldername resolves the target folder name for `gleam new .` by reading the process working directory with env::current_dir().expect(\"invalid folder\"). current_dir() fails with io::Error when the process's cwd has been deleted, unmounted, or its permissions revoked, and the expect turns that into a panic before gleam can produce its nicer UnableToFindProjectRoot error. It only triggers for the `.` special case — passing an explicit name/path never calls env::current_dir().","triggerScenarios":"Running `gleam new .` (project_root defaults to '.' at new.rs:435) from a shell whose cwd was rm -rf'd in another terminal, a cwd on an unmounted network drive or dead container mount, or a cwd the user can no longer stat due to permission changes.","commonSituations":"A rebuild script deleted and recreated the project directory while the shell stayed inside the old inode; tmux/ssh sessions resumed after their directory was removed; CI steps running in a scratch dir cleaned by a parallel job.","solutions":["Re-enter an existing directory in the same shell: `cd .` will fail, so `cd ~` (or restart the shell), then cd into the recreated directory and rerun `gleam new .`.","Recreate the directory if it was deleted: `mkdir -p /path/to/dir && cd /path/to/dir && gleam new .`.","Avoid the `.` path entirely: run `gleam new my_project` from a parent directory, which uses Utf8Path::file_name() and never touches current_dir()."],"exampleFix":"# before: shell sits in a deleted directory\ncd /tmp/gone_project   # (dir deleted elsewhere)\ngleam new .            # panics: env::current_dir() fails\n\n# after: recreate/refresh the cwd first\nmkdir -p /tmp/gone_project && cd /tmp/gone_project && gleam new .\n# or sidestep '.' entirely:\ncd /tmp && gleam new gone_project","handlingStrategy":"validation","validationCode":"// Verify the shell's cwd still exists before spawning gleam new\nmatch std::env::current_dir() {\n    Ok(dir) if dir.exists() => {}\n    _ => { // cd to a known-good dir first, or fail with a clear message\n        return Err(\"working directory was deleted; cd elsewhere\".into());\n    }\n}\n// shell equivalent: [ -d \"$(pwd -P 2>/dev/null)\" ] || cd ~","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer `gleam new <name>` over `gleam new .` — it never calls env::current_dir().","In scripts, `cd` into a freshly created directory rather than assuming an inherited cwd.","After any script that deletes/recreates directories, `cd \"$dir\"` again to refresh the shell's cwd inode."],"tags":["panic","cwd","working-directory","filesystem","gleam-new","enotdir"],"backgroundTag":"current-directory-deleted","analyzedSha":"7e623aa83da3776faee50ca4ab9a6c40124acd95","analyzedAt":"2026-08-17T00:07:02.091Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}