{"record":{"id":"9e87d45df9a41a69","repo":"swc-project/swc","slug":"destination-already-exists","errorCode":null,"errorMessage":"destination `{}` already exists","messagePattern":"destination `(.+?)` already exists","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/swc_cli_impl/src/commands/plugin.rs","lineNumber":116,"sourceCode":"    let mut f = OpenOptions::new()\n        .append(true)\n        .create(true)\n        .open(&ignore_file_path)?;\n\n    write!(f, \"{ignore}\").context(\"failed to write to .gitignore file\")?;\n\n    Ok(())\n}\n\nimpl super::CommandRunner for PluginScaffoldOptions {\n    /// Create a rust project for the plugin from template.\n    /// This largely mimic https://github.com/rust-lang/cargo/blob/master/src/cargo/ops/cargo_new.rs,\n    /// but also thinner implementation based on some assumptions like skipping\n    /// to support non-git based vcs.\n    fn execute(&self) -> Result<()> {\n        let path = &self.path;\n        if path.exists() {\n            anyhow::bail!(\"destination `{}` already exists\", path.display())\n        }\n\n        let name = get_name(self)?;\n\n        // Choose to rely on system's git binary instead of depends on git lib for now\n        // to avoid bring in large / heavy dependencies into cli binaries.\n        // Depends on our usecase grows, we can revisit this.\n        let mut base_git_cmd = if cfg!(target_os = \"windows\") {\n            let mut c = std::process::Command::new(\"cmd\");\n            c.arg(\"/C\").arg(\"git\");\n            c\n        } else {\n            std::process::Command::new(\"git\")\n        };\n\n        // init git repo\n        base_git_cmd\n            .args([\"init\", name])","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/swc-project/swc/blob/d7d74346665e36e692aa07e13d4ee3ee692ee35c/crates/swc_cli_impl/src/commands/plugin.rs#L98-L134","documentation":"Thrown by `swc plugin new` (PluginScaffoldOptions::execute) when the destination path for the new plugin project already exists on disk. The scaffolder refuses to overwrite an existing directory, mirroring cargo new behavior.","triggerScenarios":"Running `swc plugin new <path>` (or the plugin scaffold subcommand) with a path that already exists as a file or directory, including an empty leftover directory from a previous failed run.","commonSituations":"Re-running the scaffold after an interrupted attempt, choosing a name that collides with an existing folder in the cwd, or scripting the CLI without cleaning up between runs.","solutions":["Pick a fresh destination path that does not exist yet","Remove or rename the existing directory if it is a leftover: rm -rf ./my_plugin","If the existing directory is wanted content, scaffold into a temp path and merge manually"],"exampleFix":"# before\n$ swc plugin new ./my_plugin   # ./my_plugin already exists -> error\n\n# after\n$ rm -rf ./my_plugin && swc plugin new ./my_plugin\n# or\n$ swc plugin new ./my_plugin_v2","handlingStrategy":"validation","validationCode":"// Rust: check before invoking the scaffold command\nlet path = std::path::Path::new(&opts.path);\nif path.exists() {\n    anyhow::bail!(\"refusing to scaffold: {} already exists\", path.display());\n}\nPluginScaffoldOptions { path: opts.path, .. }.execute()?;","typeGuard":null,"tryCatchPattern":"// CLI wrapper\nmatch cmd.execute() {\n    Err(e) if e.to_string().contains(\"already exists\") => {\n        println!(\"destination taken; pass --force or remove the directory\");\n    }\n    other => other?,\n}","preventionTips":["In scripts, scaffold into mktemp -d directories or clean targets first","Treat 'already exists' as an expected, checkable precondition - not an exception"],"tags":["swc-cli","plugin-scaffold","filesystem","cli"],"backgroundTag":null,"analyzedSha":"d7d74346665e36e692aa07e13d4ee3ee692ee35c","analyzedAt":"2026-08-16T12:41:13.160Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}