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

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.

Solutions

  1. Change to an existing directory before running fd: `cd ~ && fd`.
  2. Pass an explicit search path so fd does not rely on cwd: `fd . /path/that/exists`.
  3. Restore or recreate the deleted directory, or remount the unmounted filesystem.

Example fix

# before (cwd was deleted)
fd
# after (explicit path, immune to cwd state)
fd . /home/user/src
Defensive patterns

Strategy: validation

Validate before calling

if [ -d "$PWD" ]; then
  fd .
else
  cd ~ && fd .
fi

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of sharkdp/fd@b422e5d8c9 (2026-08-09). Data as JSON: /api/errors/036fddcbd3eca8e5. Report an issue: GitHub.

Appendix: source

Thrown at src/cli.rs:968

                     "
                ),
        )
    }

    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 b422e5d8c9)