{"record":{"id":"77cd0b6ca3a0029e","repo":"nikivdev/code","slug":"destination-already-exists","errorCode":null,"errorMessage":"Destination already exists: {}","messagePattern":"Destination already exists: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/code.rs","lineNumber":141,"sourceCode":"                || trimmed.starts_with(\"../\")\n                || trimmed.starts_with('/')\n                || trimmed.starts_with('~')\n            {\n                let expanded = config::expand_path(trimmed);\n                if expanded.is_absolute() {\n                    expanded\n                } else {\n                    std::env::current_dir()?.join(&expanded)\n                }\n            } else {\n                // Relative name like \"zerg\" → ~/code/zerg\n                config::expand_path(DEFAULT_CODE_ROOT).join(trimmed)\n            }\n        }\n    };\n\n    if target.exists() {\n        bail!(\"Destination already exists: {}\", target.display());\n    }\n\n    if opts.dry_run {\n        println!(\n            \"Would copy template {} -> {}\",\n            template_dir.display(),\n            target.display()\n        );\n        return Ok(());\n    }\n\n    // Create parent directories if needed\n    if let Some(parent) = target.parent() {\n        if !parent.exists() {\n            fs::create_dir_all(parent).with_context(|| {\n                format!(\"failed to create parent directory {}\", parent.display())\n            })?;\n        }","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/code.rs#L123-L159","documentation":"Thrown by new_from_template (src/code.rs:141) when the destination path resolved for the new project already exists on disk. The tool refuses to overwrite, protecting existing code from being clobbered by a template copy.","triggerScenarios":"Running `f new <template> <target>` where the resolved target exists: no path arg → ./<template> already present in cwd; bare name → ~/code/<name> already exists; explicit path that already exists (even an empty directory).","commonSituations":"Re-running `f new` after a partial/interrupted previous run left the directory; creating a project with a name you already used; cwd already contains a directory named like the template.","solutions":["Choose a different destination path or project name.","Remove or rename the existing directory if it's safe to discard (`mv ~/code/name ~/code/name.bak`).","Run with --dry-run (`f new <template> <path> --dry-run`) to confirm the resolved target before creating.","Resume from the existing directory instead — if the previous run completed, no need to re-create."],"exampleFix":"// before\n$ f new rust-cli myapp\nError: Destination already exists: /home/user/code/myapp\n// after\n$ mv ~/code/myapp ~/code/myapp.bak\n$ f new rust-cli myapp   # or use --dry-run first","handlingStrategy":"validation","validationCode":"// Shell: ensure the destination is free before creating\nTARGET=\"$HOME/code/myapp\"\n[ ! -e \"$TARGET\" ] || { echo \"destination exists: $TARGET\"; exit 1; }","typeGuard":null,"tryCatchPattern":"match new_from_template(opts) {\n    Err(e) if e.to_string().contains(\"Destination already exists\") => {\n        eprintln!(\"Pick a new name or move the existing directory aside.\");\n    }\n    other => other?,\n}","preventionTips":["Run with --dry-run first to see the resolved destination path","Use unique, timestamped project names in automated scripts","Understand bare names land in ~/code/<name> — check there before re-running"],"tags":["file-exists","cli","rust","collision"],"backgroundTag":"destination-already-exists","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}