{"record":{"id":"d837eb09f2bd749c","repo":"sharkdp/fd","slug":"the-base-directory-path-is-not-a-director","errorCode":null,"errorMessage":"The '--base-directory' path '{}' is not a directory.","messagePattern":"The '--base-directory' path '(.+?)' is not a directory\\.","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/main.rs","lineNumber":134,"sourceCode":"fn print_completions(shell: clap_complete::Shell) -> Result<ExitCode> {\n    // The program name is the first argument.\n    let first_arg = env::args().next();\n    let program_name = first_arg\n        .as_ref()\n        .map(Path::new)\n        .and_then(|path| path.file_stem())\n        .and_then(|file| file.to_str())\n        .unwrap_or(\"fd\");\n    let mut cmd = Opts::command();\n    cmd.build();\n    clap_complete::generate(shell, &mut cmd, program_name, &mut std::io::stdout());\n    Ok(ExitCode::Success)\n}\n\nfn set_working_dir(opts: &Opts) -> Result<()> {\n    if let Some(ref base_directory) = opts.base_directory {\n        if !filesystem::is_existing_directory(base_directory) {\n            return Err(anyhow!(\n                \"The '--base-directory' path '{}' is not a directory.\",\n                base_directory.to_string_lossy()\n            ));\n        }\n        env::set_current_dir(base_directory).with_context(|| {\n            format!(\n                \"Could not set '{}' as the current working directory\",\n                base_directory.to_string_lossy()\n            )\n        })?;\n    }\n    Ok(())\n}\n\n/// Detect if the user accidentally supplied a path instead of a search pattern.\n///\n/// Without `--full-path`, fd matches patterns against file names, so any pattern\n/// containing a path separator can never match. This applies to the primary","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/sharkdp/fd/blob/ee20f426ddf338ac7ead5c5f00ea49258005caaf/src/main.rs#L116-L152","documentation":"set_working_dir (main.rs:131) runs before any search and validates that --base-directory points to an existing directory via filesystem::is_existing_directory. If the path is missing, a file, or inaccessible, fd refuses to chdir into it rather than failing later with a noisier syscall error.","triggerScenarios":"Passing `fd --base-directory /nonexistent`, pointing it at a regular file (`fd --base-directory ./file.txt`), or a path on an unmounted/removable drive. The check runs on every invocation that sets --base-directory.","commonSituations":"Typo in the path; relative path resolved against an unexpected cwd; deleted/moved directories; symlinks to nonexistent targets; permission errors that make is_existing_directory return false.","solutions":["Verify the path exists and is a directory: `ls -ld <path>`.","Use an absolute path to avoid cwd-relative resolution surprises.","Fix permissions if the directory exists but is unreadable."],"exampleFix":"# before\nfd --base-directory /srcc .\n\n# after\nfd --base-directory /home/user/src .","handlingStrategy":"validation","validationCode":"validate_base_dir() {\n  local d=\"$1\"\n  if [ -d \"$d\" ]; then\n    fd --base-directory \"$d\" .\n  else\n    echo \"$d is not a directory\" >&2; exit 1\n  fi\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check `-d <path>` before passing --base-directory.","Use absolute paths to avoid cwd-relative ambiguity.","In scripts, fail early with a clear message instead of letting fd error."],"tags":["filesystem","base-directory","cli","validation"],"backgroundTag":null,"analyzedSha":"ee20f426ddf338ac7ead5c5f00ea49258005caaf","analyzedAt":"2026-08-09T08:21:40.573Z","contentChangedAt":"2026-08-09T08:21:40.573Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}