{"record":{"id":"3b9b440507288c03","repo":"jdx/mise","slug":"brew-cask-completion-target-already-exists-a-3b9b44","errorCode":null,"errorMessage":"brew-cask: completion target '{}' already exists and is not owned by cask '{}'","messagePattern":"brew-cask: completion target '(.+?)' already exists and is not owned by cask '(.+?)'","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/system/packages/brew/cask/mod.rs","lineNumber":2688,"sourceCode":"    }\n    if let Some(parent) = target.parent() {\n        create_dir_all_elevating(parent)?;\n    }\n    ensure_completion_target_replaceable(cask, artifacts, target)?;\n    make_symlink_elevating(&caskroom_completion, target)?;\n    Ok(())\n}\n\nfn ensure_completion_target_replaceable(\n    cask: &Cask,\n    artifacts: &CaskArtifacts,\n    target: &Path,\n) -> Result<()> {\n    let Ok(metadata) = target.symlink_metadata() else {\n        return Ok(());\n    };\n    if !metadata.file_type().is_symlink() {\n        bail!(\n            \"brew-cask: completion target '{}' already exists and is not owned by cask '{}'\",\n            target.display(),\n            cask.token\n        );\n    }\n    let link_target = std::fs::read_link(target)?;\n    let resolved = resolve_symlink_target(target, link_target);\n    let token_dir = caskroom_token_dir(&cask.token);\n    if path_starts_with_resolved_root(&resolved, &token_dir) {\n        return Ok(());\n    }\n    for completion in &artifacts.completions {\n        if completion.target_path()? != target {\n            continue;\n        }\n        if let Some(source) = appdir_artifact_source(&completion.source, &artifacts.apps)?\n            && file::same_file(&resolved, &source)\n        {","sourceCodeStart":2670,"sourceCodeEnd":2706,"githubUrl":"https://github.com/jdx/mise/blob/afd2eddd3a50c16190efc1c7e94404b48f72af57/src/system/packages/brew/cask/mod.rs#L2670-L2706","documentation":"When linking a completion artifact, mise refuses to overwrite an existing completion path unless it is a symlink (i.e., previously managed by mise or pointing into the cask). If a real file or directory already occupies the target, this error is thrown to avoid clobbering data mise does not own, identified by the cask token.","triggerScenarios":"`target.symlink_metadata()` succeeds and `!metadata.file_type().is_symlink()` — a regular file, directory, or other non-symlink already exists at the completion target path before this cask is linked.","commonSituations":"The user (or Homebrew previously) installed a real completion file at the same path; another package manager owns the completion; a previous non-symlink install left files behind.","solutions":["Inspect the existing file at the target path and back it up if you want to keep it","Remove or rename the conflicting file/directory and re-run the install","Verify the existing completion isn't owned by another tool (e.g. a system package) before deleting","If another tool owns it, configure mise/the cask to use a different completion target"],"exampleFix":"// before: real file blocks the link\nmv ~/.zsh/completions/_mytool ~/.zsh/completions/_mytool.bak\n// after: install creates a mise-owned symlink\nmise install <cask>","handlingStrategy":"try-catch","validationCode":"p=<target-path>; if [ -e \"$p\" ] && [ ! -L \"$p\" ]; then echo \"non-symlink exists at $p — will conflict\"; fi","typeGuard":null,"tryCatchPattern":"match result {\n  Err(e) if e.contains(\"already exists and is not owned by cask\") => {\n    eprintln!(\"back up and remove the existing non-symlink at the target, then reinstall: {e}\");\n  }\n  Err(e) => return Err(e),\n  Ok(v) => v,\n}","preventionTips":["Check completion target paths for pre-existing files before installing a cask","Avoid mixing Homebrew/manual completion installs with mise-managed ones at the same paths","Keep one owner per completion path"],"tags":["brew-cask","completions","symlink","file-conflict"],"backgroundTag":"file-already-exists","analyzedSha":"afd2eddd3a50c16190efc1c7e94404b48f72af57","analyzedAt":"2026-09-09T01:38:25.179Z","contentChangedAt":"2026-09-09T01:38:25.179Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}