nikivdev/code · error
Path must be a directory: {}
Error message
Path must be a directory: {} What it means
import_external_path imports an external project directory into the current project's ext/ folder. After normalize_path and an existence check, it requires the path to be a directory; a plain file is rejected because the import copies a whole workspace tree, not individual files.
Source
Thrown at src/ext.rs:139
fn disable_extension(name: &str) -> Result<()> {
flow_config::disable_extension(name)?;
println!("Disabled extension {}", name);
Ok(())
}
fn init_extension(name: &str, force: bool) -> Result<()> {
let dir = flow_config::init_extension(name, force)?;
println!("Initialized extension {} at {}", name, dir.display());
Ok(())
}
fn import_external_path(path: &str) -> Result<()> {
let source = normalize_path(path)?;
if !source.exists() {
bail!("Path not found: {}", source.display());
}
if !source.is_dir() {
bail!("Path must be a directory: {}", source.display());
}
let project_root = project_root_from_cwd();
let ext_dir = project_root.join("ext");
fs::create_dir_all(&ext_dir)?;
let name = source
.file_name()
.and_then(|n| n.to_str())
.map(|s| s.to_string())
.filter(|s| !s.trim().is_empty())
.unwrap_or_else(|| "external".to_string());
let dest = ext_dir.join(&name);
if dest.exists() {
bail!("Destination already exists: {}", dest.display());
}
View on GitHub (pinned to a747e741ae)
Solutions
- Pass the directory containing the project/workspace, not a file inside it.
- If you meant a subdirectory of a repo, give the repo root or workspace directory.
- Verify with `ls -la <path>` that the target is a directory before running the import.
Example fix
// before
import_external_path("./myproject/Cargo.toml")?;
// after
import_external_path("./myproject")?; Defensive patterns
Strategy: validation
Validate before calling
let p = std::path::Path::new(path);
if !p.exists() || !p.is_dir() {
return Err(anyhow!("{} must be an existing directory", p.display()));
}
import_external_path(path)?; Type guard
fn is_importable_dir(p: &str) -> bool {
std::path::Path::new(p).is_dir()
} Try / catch
match import_external_path(path) {
Ok(()) => {},
Err(e) if e.to_string().starts_with("Path must be a directory") => {
eprintln!("Pass a directory, not a file: {path}");
}
Err(e) => return Err(e),
} Prevention
- Resolve symlinks (canonicalize) before checking the path kind.
- Add an is_dir() assertion in scripts that invoke the import command.
- Prefer directory pickers/autocomplete limited to directories.
When it happens
Trigger: Calling import_external_path with a path that exists on disk but is a regular file, e.g. import_external_path("./config.toml") or a symlink resolving to a file.
Common situations: Passing a config file or lockfile instead of the project folder; shell tab-completion selecting a file; pointing at a nested file inside the repo you meant to import.
Related errors
- Relative path cannot be empty.
- Relative path must not be absolute.
- env file not found: {}
- Path not found: {}
- Destination already exists: {}
AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01).
Data as JSON: /api/errors/fdbf8191504187d7.
Report an issue: GitHub.