{"record":{"id":"123e7873764f0e48","repo":"vectordotdev/vector","slug":"already-exists","errorCode":null,"errorMessage":"{} already exists","messagePattern":"(.+?) already exists","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"vdev/src/commands/changelog/new.rs","lineNumber":40,"sourceCode":"        FRAGMENT_TYPES.iter().map(|t| t.name)\n    ))]\n    fragment_type: String,\n    /// Unique slug (used as the filename prefix, e.g. `env_var_interpolation`).\n    slug: String,\n}\n\nimpl Cli {\n    pub fn exec(self) -> Result<()> {\n        validate_slug(&self.slug)?;\n\n        let repo_root = paths::find_repo_root()?;\n        let dir = repo_root.join(CHANGELOG_DIR);\n        if !dir.is_dir() {\n            bail!(\"{} does not exist\", dir.display());\n        }\n        let file = dir.join(format!(\"{}.{}.md\", self.slug, self.fragment_type));\n        if file.exists() {\n            bail!(\"{} already exists\", file.display());\n        }\n\n        let author = detect_gh_handle().unwrap_or_else(|| TODO_HANDLE.to_string());\n        let Some(entry) = FRAGMENT_TYPES\n            .iter()\n            .find(|t| t.name == self.fragment_type.as_str())\n        else {\n            bail!(\"unknown fragment type '{}'\", self.fragment_type);\n        };\n        let content = render_template(entry, &author);\n        fs::write(&file, content)?;\n\n        // `git add` the new fragment so the checker (which scans `git diff --diff-filter=A`)\n        // picks it up immediately without a manual staging step. Report the failure if it\n        // happens — the file is on disk, but the checker won't see it until it's staged.\n        let status = Command::new(\"git\")\n            .args([\"add\", \"--\"])\n            .arg(&file)","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/vectordotdev/vector/blob/bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013/vdev/src/commands/changelog/new.rs#L22-L58","documentation":"`vdev changelog new` refuses to overwrite an existing fragment. In `New::exec` (vdev/src/commands/changelog/new.rs:30), after building the target path `changelog.d/<slug>.<type>.md`, it checks `file.exists()` and bails with \"<path> already exists\" if a fragment with the same slug and type is already present.","triggerScenarios":"Running `vdev changelog new <slug> <type>` when `changelog.d/<slug>.<type>.md` already exists — e.g. re-running the command after a previous successful run, or reusing a slug that collides with an existing fragment.","commonSituations":"Re-running the command after an interrupted session where the file was already written; picking a generic slug (like `fix-bug`) that another contributor already used; scripting the command idempotently without checking existence.","solutions":["Choose a different, more specific slug (e.g. include a ticket number).","Edit the existing `changelog.d/<slug>.<type>.md` file instead of creating a new one.","Delete the existing fragment first if it was created by mistake, then re-run the command."],"exampleFix":"// before\nvdev changelog new fix-bug error   # changelog.d/fix-bug.error.md exists\n// after\nvdev changelog new fix-bug-12345 error","handlingStrategy":"validation","validationCode":"let path = format!(\"changelog.d/{slug}.{fragment_type}.md\");\nif std::path::Path::new(&path).exists() {\n    eprintln!(\"fragment already exists at {path}; edit it or pick another slug\");\n}","typeGuard":null,"tryCatchPattern":"if let Err(e) = changelog_new::New { slug, fragment_type }.exec() {\n    eprintln!(\"{e:#}\"); // includes the conflicting file path\n}","preventionTips":["Use unique, specific slugs (ticket/issue number) to avoid collisions.","Check `ls changelog.d/` before creating a fragment.","Edit the existing fragment instead of creating a duplicate."],"tags":["changelog","cli","filesystem"],"backgroundTag":"file-already-exists","analyzedSha":"bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013","analyzedAt":"2026-09-16T02:53:35.741Z","contentChangedAt":"2026-09-16T02:53:35.741Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}