{"record":{"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":"console","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/cli.rs","lineNumber":968,"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":950,"sourceCodeEnd":973,"githubUrl":"https://github.com/sharkdp/fd/blob/b422e5d8c9cffaa1ae43ba68e7b97a60fb3e8ae5/src/cli.rs#L950-L973","documentation":"fd validates that the current working directory ('./') still exists when no explicit search path is passed on the command line. ensure_current_directory_exists() calls filesystem::is_existing_directory on './' and bails if the stat fails, because a deleted/unmounted cwd would make the default recursive walk silently scan nothing or error deeper inside ignore::WalkBuilder. This is a fail-fast guard in cli.rs:967, invoked from Opts::search_paths() at cli.rs:704.","triggerScenarios":"Running `fd` (no path arg) from a terminal whose cwd was rm -rf'd, replaced, or unmounted in another shell/process after fd started but before path resolution; running inside a container whose mount was removed; NFS stale handles.","commonSituations":"A build script deletes and recreates the build dir while a watch loop runs fd in it; terminal left in a directory removed by a package manager update; mount-point teardown on shared storage.","solutions":["Change to an existing directory before running fd: `cd ~ && fd`.","Pass an explicit search path so fd does not rely on cwd: `fd . /path/that/exists`.","Restore or recreate the deleted directory, or remount the unmounted filesystem."],"exampleFix":"# before (cwd was deleted)\nfd\n# after (explicit path, immune to cwd state)\nfd . /home/user/src","handlingStrategy":"validation","validationCode":"if [ -d \"$PWD\" ]; then\n  fd .\nelse\n  cd ~ && fd .\nfi","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass an explicit search path to fd so it never depends on cwd.","In watch loops that rebuild/recreate directories, chdir to a stable parent before invoking fd.","Validate the working directory exists before launching long-lived tools."],"tags":["filesystem","working-directory","cli","environment"],"backgroundTag":null,"analyzedSha":"b422e5d8c9cffaa1ae43ba68e7b97a60fb3e8ae5","analyzedAt":"2026-08-09T08:21:40.573Z","contentChangedAt":"2026-08-09T08:21:40.573Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}