{"record":{"id":"b47fcfe030d67cd0","repo":"jdx/mise","slug":"rename-exe-cannot-rename-to-target-alr","errorCode":null,"errorMessage":"rename_exe: cannot rename '{}' to '{}': target already exists. Check for duplicate or overlapping rename_exe mappings.","messagePattern":"rename_exe: cannot rename '(.+?)' to '(.+?)': target already exists\\. Check for duplicate or overlapping rename_exe mappings\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/backend/static_helpers.rs","lineNumber":1234,"sourceCode":"}\n\n/// Renames `path` (named `file_name`) to `target` within `dir`, preserving any\n/// required extension and ensuring the result is executable. A collision on the\n/// target (two mappings pointing at the same name, or the archive already\n/// containing that name) is unsatisfiable, so it fails the install loudly rather\n/// than silently dropping a binary and reporting success.\nfn finish_rename(dir: &Path, path: &Path, file_name: &str, target: &str) -> eyre::Result<()> {\n    let target_path = keep_required_extensions(dir, file_name, target, dir.join(target));\n    // Ensure the binary is executable whether or not we move it: ZIP archives drop\n    // the exec bit, and the file may already carry the desired name.\n    if !file::is_executable(path) {\n        file::make_executable(path)?;\n    }\n    if path == target_path {\n        return Ok(());\n    }\n    if target_path.exists() {\n        bail!(\n            \"rename_exe: cannot rename '{}' to '{}': target already exists. \\\n             Check for duplicate or overlapping rename_exe mappings.\",\n            path.display(),\n            target_path.display()\n        );\n    }\n    file::rename(path, &target_path)?;\n    debug!(\"Renamed {} to {}\", path.display(), target_path.display());\n    Ok(())\n}\n\n/// Helper function to rename executable inside a macOS .app bundle\nfn rename_executable_in_app_bundle(\n    macos_dir: &Path,\n    target_path: &Path,\n    tool_name: Option<&str>,\n) -> eyre::Result<bool> {\n    // Find the first executable in the Contents/MacOS directory","sourceCodeStart":1216,"sourceCodeEnd":1252,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/backend/static_helpers.rs#L1216-L1252","documentation":"During a rename_exe operation, mise refuses to overwrite an existing target file. finish_rename checks target_path.exists() before renaming, so overlapping renames cannot silently clobber binaries. The error points at duplicate or conflicting rename_exe mappings in the tool config.","triggerScenarios":"apply_rename_exe encounters a destination path that already exists on disk and is not the source itself — typically two rename_exe entries (or a rename plus a real file) mapping different sources to the same target name.","commonSituations":"Two tools in the same package shipping a binary with the same name; a leftover file from a previous install plus a new rename mapping; duplicated config entries.","solutions":["Review rename_exe mappings for duplicates and make each target unique","Delete the stale target file from the install directory and retry the install","If the target is a legitimately shipped binary, remove the redundant rename entry"],"exampleFix":"# before\n[[bin]]\nrename_exe = \"tool\"\n[[bin]]\nrename_exe = \"tool\"   # duplicate target\n# after\n[[bin]]\nrename_exe = \"tool-a\"\n[[bin]]\nrename_exe = \"tool-b\"","handlingStrategy":"validation","validationCode":"import os\n# preflight before rename/install\ntargets = [m['rename_exe'] for m in mappings]\nassert len(targets) == len(set(targets)), 'duplicate rename_exe targets'\nclashes = [t for t in targets if os.path.exists(os.path.join(install_dir, t))]\nassert not clashes, f'targets already exist: {clashes}'","typeGuard":null,"tryCatchPattern":"try:\n    install()\nexcept RuntimeError as e:\n    if 'target already exists' in str(e):\n        cleanup_stale_files(install_dir)\n        install()\n    else:\n        raise","preventionTips":["Make rename_exe targets unique","Clean install dirs between versions","Detect overlapping mappings at config load"],"tags":["filesystem","config-conflict","rename"],"backgroundTag":"file-already-exists","analyzedSha":"533346cc374382b41ec5ff70536252b2e96e725c","analyzedAt":"2026-09-17T13:35:38.149Z","contentChangedAt":"2026-09-17T13:35:38.149Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}