{"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/41532d114e2ba565fb5367d606c111b29b96450c/src/main.rs#L116-L152","documentation":"Thrown by set_working_dir in src/main.rs:134 when --base-directory resolves via filesystem::is_existing_directory to something that is not a directory (a regular file, a broken path, or a path that doesn't exist at all). fd chdirs into that directory before walking, so it must be a real directory.","triggerScenarios":"Passing 'fd --base-directory /etc/passwd' (a file), 'fd --base-directory /no/such/dir', or a path that exists only as a symlink to a missing target.","commonSituations":"Config typo; using a tilde that wasn't expanded (e.g. quoted '~'); pointing at a path on an unmounted volume; copy-pasting a file path where a directory was expected.","solutions":["Confirm the path exists and is a directory: 'test -d <path> && fd --base-directory <path> ...'.","Use an unquoted tilde or $HOME so the shell expands it: 'fd --base-directory \"$HOME\"/src'.","Drop --base-directory and pass the directory as the search path positional argument instead."],"exampleFix":"// before\nfd --base-directory /etc/passwd foo\n\n// after\nfd --base-directory /etc foo","handlingStrategy":"validation","validationCode":"if [ ! -d \"$BASE_DIR\" ]; then\n  echo \"--base-directory is not a directory: $BASE_DIR\" >&2; exit 1\nfi\nfd --base-directory \"$BASE_DIR\" \"$@\"","typeGuard":"fn is_real_dir(p: &std::path::Path) -> bool {\n    p.is_dir() // true only for existing directories\n}","tryCatchPattern":null,"preventionTips":["Gate --base-directory behind 'test -d' in scripts.","Let the shell expand $HOME/tilde; don't quote them literally.","Prefer a positional search path over --base-directory when unsure."],"tags":["base-directory","filesystem","cli-flag","validation"],"analyzedSha":"41532d114e2ba565fb5367d606c111b29b96450c","analyzedAt":"2026-08-06T01:39:28.509Z","schemaVersion":2}