{"record":{"id":"94446a74fe7de568","repo":"jdx/mise","slug":"brew-cask-binary-artifact-was-staged-but-sym-94446a","errorCode":null,"errorMessage":"brew-cask: binary artifact '{}' was staged but symlink target '{}' does not exist","messagePattern":"brew-cask: binary artifact '(.+?)' was staged but symlink target '(.+?)' does not exist","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/system/packages/brew/cask/mod.rs","lineNumber":3486,"sourceCode":"fn cask_appdir(apps: &[AppArtifact]) -> Result<PathBuf> {\n    let prefix_app_dir = prefix::prefix().join(\"Applications\");\n    for app in apps {\n        if app_target_path(app.target_name())?.starts_with(&prefix_app_dir) {\n            return Ok(prefix_app_dir);\n        }\n    }\n    target_app_dir()\n}\n\nfn link_binary(caskroom: &Path, appdir: &Path, binary: &BinaryArtifact) -> Result<()> {\n    let caskroom_binary = caskroom_binary_path(caskroom, appdir, binary)?;\n    if !caskroom_binary.is_file() {\n        if caskroom_binary\n            .symlink_metadata()\n            .is_ok_and(|metadata| metadata.file_type().is_symlink())\n        {\n            let target = std::fs::read_link(&caskroom_binary)?;\n            bail!(\n                \"brew-cask: binary artifact '{}' was staged but symlink target '{}' does not exist\",\n                binary.source,\n                target.display()\n            );\n        }\n        bail!(\n            \"brew-cask: binary artifact '{}' was not staged\",\n            binary.source\n        );\n    }\n    let target = binary.target_path(appdir)?;\n    if let Some(parent) = target.parent() {\n        create_dir_all_elevating(parent)?;\n    }\n    make_symlink_elevating(&caskroom_binary, &target)?;\n    Ok(())\n}\n","sourceCodeStart":3468,"sourceCodeEnd":3504,"githubUrl":"https://github.com/jdx/mise/blob/afd2eddd3a50c16190efc1c7e94404b48f72af57/src/system/packages/brew/cask/mod.rs#L3468-L3504","documentation":"After staging, a binary artifact that should exist in the caskroom is a dangling symlink: the staged path has symlink metadata but the link's target does not exist. mise treats the artifact as unusable and reports both the declared source and the broken link target.","triggerScenarios":"linking/validating a staged binary whose caskroom path is a symlink pointing to a file that was never staged or has been deleted, detected via read_link followed by the existence check.","commonSituations":"A previous failed/partial install left a broken symlink in the caskroom, an antivirus or cleanup tool removed the link target, or the cask artifact layout changed between versions leaving stale links.","solutions":["Delete the broken symlink in the caskroom and reinstall the cask","Verify the cask payload actually contains the file the symlink points to","Reinstall the cask version cleanly (remove the versioned caskroom dir first)"],"exampleFix":"// shell before\nls -l ~/Library/Caches/mise/brew-cask/caskroom/<cask>/.../bin/foo  # -> /missing/target\n// after\nrm ~/Library/Caches/mise/brew-cask/caskroom/<cask>/<version>/bin/foo && mise install","handlingStrategy":"validation","validationCode":"if p.symlink_metadata().map(|m| m.file_type().is_symlink()).unwrap_or(false) {\n    let t = std::fs::read_link(&p)?;\n    if !t.exists() {\n        std::fs::remove_file(&p).ok(); // drop dangling link before reinstall\n    }\n}","typeGuard":"fn is_dangling_symlink(p: &Path) -> bool {\n    p.symlink_metadata().map(|m| m.file_type().is_symlink()).unwrap_or(false)\n        && p.metadata().is_err()\n}","tryCatchPattern":"match install_result {\n    Err(e) if e.to_string().contains(\"symlink target\") => {\n        clean_caskroom_version(version);\n        install_result = install(version);\n    }\n    _ => {}\n}","preventionTips":["Check for and remove dangling symlinks in the caskroom before upgrading","Avoid external tools that prune symlink targets inside mise caches"],"tags":["brew-cask","symlink","staging"],"backgroundTag":"broken-symlink","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"}