{"record":{"id":"3f2693526e25d5f0","repo":"nikivdev/code","slug":"destination-already-exists-3f2693","errorCode":null,"errorMessage":"Destination already exists: {}","messagePattern":"Destination already exists: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/ext.rs","lineNumber":155,"sourceCode":"    }\n    if !source.is_dir() {\n        bail!(\"Path must be a directory: {}\", source.display());\n    }\n\n    let project_root = project_root_from_cwd();\n    let ext_dir = project_root.join(\"ext\");\n    fs::create_dir_all(&ext_dir)?;\n\n    let name = source\n        .file_name()\n        .and_then(|n| n.to_str())\n        .map(|s| s.to_string())\n        .filter(|s| !s.trim().is_empty())\n        .unwrap_or_else(|| \"external\".to_string());\n\n    let dest = ext_dir.join(&name);\n    if dest.exists() {\n        bail!(\"Destination already exists: {}\", dest.display());\n    }\n\n    let source_workspace = prepare_source_workspace(&source, &project_root)?;\n    copy_dir_all(&source_workspace, &dest)?;\n    add_gitignore_entry(&project_root, \"ext/\")?;\n    if let Err(err) = code::migrate_sessions_between_paths(&source, &dest, false, false, false) {\n        eprintln!(\"WARN failed to migrate sessions: {err}\");\n    }\n\n    println!(\n        \"Copied {} -> {}\",\n        source_workspace.display(),\n        dest.display()\n    );\n    Ok(())\n}\n\nfn normalize_path(path: &str) -> Result<PathBuf> {","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/ext.rs#L137-L173","documentation":"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.","triggerScenarios":"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.","commonSituations":"Re-running an import after a partial failure; importing multiple externals that share a default name; stale ext/ entries from renamed sources.","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."],"exampleFix":"// before\n// ext/external already exists from an earlier import\nimport_external_path(\"~/work/other-repo\")?;\n// after\nstd::fs::remove_dir_all(\"ext/external\")?; // or pick a unique name\nimport_external_path(\"~/work/other-repo\")?;","handlingStrategy":"validation","validationCode":"let dest = project_root.join(\"ext\").join(&name);\nif dest.exists() {\n    return Err(anyhow!(\"{} already exists; remove or rename first\", dest.display()));\n}\nimport_external_path(path)?;","typeGuard":"fn dest_is_free(project_root: &Path, name: &str) -> bool {\n    !project_root.join(\"ext\").join(name).exists()\n}","tryCatchPattern":"if let Err(e) = import_external_path(path) {\n    if e.to_string().contains(\"Destination already exists\") {\n        eprintln!(\"Remove ext/<name> or choose a new name, then retry\");\n    } else { return Err(e); }\n}","preventionTips":["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."],"tags":["filesystem","duplicate-destination","cli"],"backgroundTag":"destination-already-exists","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}