{"id":"036fddcbd3eca8e5","repo":"sharkdp/fd","slug":"could-not-retrieve-current-directory-has-it-been","errorCode":null,"errorMessage":"Could not retrieve current directory (has it been deleted?).","messagePattern":"Could not retrieve current directory \\(has it been deleted\\?\\)\\.","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/cli.rs","lineNumber":967,"sourceCode":"                     \"\n                ),\n        )\n    }\n\n    fn augment_args_for_update(cmd: Command) -> Command {\n        Self::augment_args(cmd)\n    }\n}\n\nfn parse_millis(arg: &str) -> Result<Duration, std::num::ParseIntError> {\n    Ok(Duration::from_millis(arg.parse()?))\n}\n\nfn ensure_current_directory_exists(current_directory: &Path) -> anyhow::Result<()> {\n    if filesystem::is_existing_directory(current_directory) {\n        Ok(())\n    } else {\n        Err(anyhow!(\n            \"Could not retrieve current directory (has it been deleted?).\"\n        ))\n    }\n}\n","sourceCodeStart":949,"sourceCodeEnd":972,"githubUrl":"https://github.com/sharkdp/fd/blob/41532d114e2ba565fb5367d606c111b29b96450c/src/cli.rs#L949-L972","documentation":"Thrown by ensure_current_directory_exists in src/cli.rs:967 when filesystem::is_existing_directory(cwd) returns false. fd captures the process cwd early and verifies it still resolves to a real directory; this guards every downstream operation that builds paths relative to '.'. The parenthetical '(has it been deleted?)' reflects the most common cause, but a cwd replaced by a file or a broken symlink also triggers it.","triggerScenarios":"In another terminal/session the cwd was rmdir'd, renamed, or replaced by a file between the shell's fork and fd's path check; running fd from a directory on a filesystem that has since been unmounted; cwd symlink chain dangling.","commonSituations":"A build job that deletes its working folder and then re-runs fd from the same shell; container teardown unmounting the volume that held cwd; NFS dropout leaving cwd stale.","solutions":["cd into a directory that exists: 'cd ~ && fd <pattern>'.","Recreate or restore the deleted directory, then re-run fd from the original shell.","Run fd with an explicit path argument and avoid relying on cwd: 'fd <pattern> /absolute/path'."],"exampleFix":"// before\npwd   # /tmp/just-deleted\nfd foo\n\n// after\ncd ~ && fd foo /tmp/just-deleted   # search an existing path instead","handlingStrategy":"validation","validationCode":"if [ \"$(pwd -P 2>/dev/null)\" ]; then fd \"$@\"; else\n  echo \"cwd missing; cd somewhere valid first\" >&2; exit 1\nfi","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Before launching fd from scripts that mutate directories, verify 'pwd -P' still succeeds.","Pass explicit absolute search paths so fd does not depend on cwd.","Avoid deleting the working directory of a long-lived shell session."],"tags":["filesystem","cwd","concurrency","environment"],"analyzedSha":"41532d114e2ba565fb5367d606c111b29b96450c","analyzedAt":"2026-08-06T01:39:28.509Z","schemaVersion":2}