{"record":{"id":"9e87d45df9a41a69","repo":"swc-project/swc","slug":"destination-already-exists","errorCode":null,"errorMessage":"destination `{}` already exists","messagePattern":"destination `(.+?)` already exists","errorType":"validation","errorClass":null,"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/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_cli_impl/src/commands/plugin.rs#L98-L134","documentation":"`swc plugin new` refuses to scaffold a plugin project into an existing path: if the destination exists on disk it bails immediately, mirroring `cargo new` behavior (crates/swc_cli_impl/src/commands/plugin.rs). This prevents overwriting user data with the template.","triggerScenarios":"Running `swc plugin new my-plugin` when ./my-plugin already exists (file or directory); re-running a scaffold after a partial failure.","commonSituations":"Retrying after an interrupted scaffold left the directory behind; name collisions with existing packages; scripting scaffold commands without existence checks.","solutions":["Choose a different destination path or plugin name","Or remove/move the existing directory, then re-run","For partial scaffolds, clear the leftover directory first"],"exampleFix":"# before\nswc plugin new my-plugin   # ./my-plugin exists\n# after\nrm -rf ./my-plugin && swc plugin new my-plugin   # or: swc plugin new my-plugin-v2","handlingStrategy":"validation","validationCode":"// JavaScript - guard scaffold destination before running the command\nimport fs from 'node:fs';\nif (fs.existsSync(dest)) {\n  throw new Error(`destination already exists: ${dest}`);\n}\n// then: spawn `swc plugin new ${dest}`","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check path existence before scaffolding in generated scripts","Clean up partial scaffold directories before retrying","Namespace plugin names to avoid collisions in monorepos"],"tags":["swc-cli","plugin","scaffold","filesystem"],"backgroundTag":"destination-path-exists","analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","contentChangedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}