sharkdp/fd · error · anyhow::Error
Could not retrieve current directory (has it been deleted?).
Error message
Could not retrieve current directory (has it been deleted?).
What it means
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.
Source
Thrown at src/cli.rs:967
"
),
)
}
fn augment_args_for_update(cmd: Command) -> Command {
Self::augment_args(cmd)
}
}
fn parse_millis(arg: &str) -> Result<Duration, std::num::ParseIntError> {
Ok(Duration::from_millis(arg.parse()?))
}
fn ensure_current_directory_exists(current_directory: &Path) -> anyhow::Result<()> {
if filesystem::is_existing_directory(current_directory) {
Ok(())
} else {
Err(anyhow!(
"Could not retrieve current directory (has it been deleted?)."
))
}
}
View on GitHub (pinned to 41532d114e)
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'.
Example fix
// before pwd # /tmp/just-deleted fd foo // after cd ~ && fd foo /tmp/just-deleted # search an existing path instead
Defensive patterns
Strategy: validation
Validate before calling
if [ "$(pwd -P 2>/dev/null)" ]; then fd "$@"; else echo "cwd missing; cd somewhere valid first" >&2; exit 1 fi
Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
AI-assisted analysis of sharkdp/fd@41532d114e (2026-08-06).
Data as JSON: /data/errors/036fddcbd3eca8e5.json.
Report an issue: GitHub.