nikivdev/code · error
Destination already exists: {}
Error message
Destination already exists: {} What it means
The import destination ext/<name> (name taken from the source config, defaulting to "external") already exists, and import_external_path refuses to clobber existing directories. This protects previously imported externals from being silently replaced.
Source
Thrown at src/ext.rs:155
}
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());
}
let source_workspace = prepare_source_workspace(&source, &project_root)?;
copy_dir_all(&source_workspace, &dest)?;
add_gitignore_entry(&project_root, "ext/")?;
if let Err(err) = code::migrate_sessions_between_paths(&source, &dest, false, false, false) {
eprintln!("WARN failed to migrate sessions: {err}");
}
println!(
"Copied {} -> {}",
source_workspace.display(),
dest.display()
);
Ok(())
}
fn normalize_path(path: &str) -> Result<PathBuf> {View on GitHub (pinned to a747e741ae)
Solutions
- Delete or rename the existing ext/<name> directory, then re-run the import.
- Set a distinct name for the source so the destination differs.
- Check the destination with a quick exists() probe before importing.
Example fix
// before
// ext/external already exists from an earlier import
import_external_path("~/work/other-repo")?;
// after
std::fs::remove_dir_all("ext/external")?; // or pick a unique name
import_external_path("~/work/other-repo")?; Defensive patterns
Strategy: validation
Validate before calling
let dest = project_root.join("ext").join(&name);
if dest.exists() {
return Err(anyhow!("{} already exists; remove or rename first", dest.display()));
}
import_external_path(path)?; Type guard
fn dest_is_free(project_root: &Path, name: &str) -> bool {
!project_root.join("ext").join(name).exists()
} Try / catch
if let Err(e) = import_external_path(path) {
if e.to_string().contains("Destination already exists") {
eprintln!("Remove ext/<name> or choose a new name, then retry");
} else { return Err(e); }
} Prevention
- Give each external a unique name in its config instead of relying on the "external" default.
- Clean up ext/ after aborted imports.
- Script the existence check before every import run.
When it happens
Trigger: Running the import command twice for the same external; two different sources resolving to the same derived name; a leftover directory from a failed prior import; the default name "external" colliding with an existing ext/external folder.
Common situations: Re-running an import after a partial failure; importing multiple externals that share a default name; stale ext/ entries from renamed sources.
Related errors
- env file not found: {}
- Path not found: {}
- Path must be a directory: {}
- Workspace {} already exists at {}
- {} is not inside a git repository
AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01).
Data as JSON: /api/errors/3f2693526e25d5f0.
Report an issue: GitHub.