{"record":{"id":"5e8809048b7df93d","repo":"jdx/mise","slug":"brew-cask-appdir-must-prefix-a-binary-target-5e8809","errorCode":null,"errorMessage":"brew-cask: $APPDIR must prefix a binary target","messagePattern":"brew-cask: \\$APPDIR must prefix a binary target","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/system/packages/brew/cask/paths.rs","lineNumber":281,"sourceCode":"        .map(|root| root.display().to_string())\n        .collect::<Vec<_>>()\n        .join(\" or \")\n}\n\npub(super) fn binary_target_path(target_name: &str, appdir: &Path) -> Result<PathBuf> {\n    if target_name.contains('\\0') {\n        bail!(\"brew-cask: binary target contains NUL\");\n    }\n    if let Some(relative) = target_name.strip_prefix(\"$APPDIR/\") {\n        let relative = Path::new(relative);\n        reject_appdir_escape(relative, \"binary $APPDIR target\", target_name)?;\n        if !allowed_appdir_roots()?.iter().any(|root| root == appdir) {\n            bail!(\"brew-cask: invalid appdir '{}'\", appdir.display());\n        }\n        return Ok(appdir.join(relative));\n    }\n    if target_name.contains(\"$APPDIR\") {\n        bail!(\"brew-cask: $APPDIR must prefix a binary target\");\n    }\n    let prefix = prefix::prefix();\n    let prefix_str = prefix.to_string_lossy();\n    let target_name = target_name.replace(\"$HOMEBREW_PREFIX\", prefix_str.as_ref());\n    let path = PathBuf::from(&target_name);\n    let target = if path.is_absolute() {\n        path\n    } else if target_name.contains('/') {\n        prefix.join(path)\n    } else {\n        prefix.join(\"bin\").join(path)\n    };\n    if target\n        .components()\n        .any(|component| matches!(component, Component::ParentDir))\n    {\n        bail!(\n            \"brew-cask: binary target '{}' must not contain '..'\",","sourceCodeStart":263,"sourceCodeEnd":299,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/system/packages/brew/cask/paths.rs#L263-L299","documentation":"This error is thrown by `binary_target_path` in src/system/packages/brew/cask/paths.rs when a cask's binary target name contains the `$APPDIR` placeholder but does not start with it (e.g. `bin/$APPDIR/foo` or `$APPDIR_EXTRA/foo`). The library only supports `$APPDIR` as a leading prefix that is then replaced with the validated appdir; any other placement is ambiguous and rejected to avoid expanding the placeholder into an unvalidated path position.","triggerScenarios":"Calling `binary_target_path(target_name, appdir)` where `target_name.contains(\"$APPDIR\")` is true but `target_name.strip_prefix(\"$APPDIR/\")` returns None — for example `$APPDIR` appearing mid-path, without the following slash, or after other components. Reached via `target_path` or `binary_targets_must_stay_under_an_allowed_root`.","commonSituations":"A hand-edited cask formula with `$APPDIR` placed after a `bin/` or other directory component; a typo like `$$APPDIR` or `$APPDIRS`; concatenating strings that inserts the placeholder in the wrong spot; copying a target from another cask and rearranging the path.","solutions":["Rewrite the target so `$APPDIR/` is the leading prefix: `\"$APPDIR/<relative path>\"`","If the binary really lives under the Homebrew prefix instead of the appdir, drop `$APPDIR` and use a normal path (e.g. `$HOMEBREW_PREFIX/bin/foo` or a bare name)","Check for typos in the placeholder (extra characters before or after `$APPDIR`)"],"exampleFix":"// before\nbinary_target_path(\"bin/$APPDIR/mytool\", &appdir)\n// error: brew-cask: $APPDIR must prefix a binary target\n\n// after\nbinary_target_path(\"$APPDIR/mytool\", &appdir)","handlingStrategy":"validation","validationCode":"fn appdir_target_is_valid(target: &str) -> bool {\n    target.starts_with(\"$APPDIR/\") || !target.contains(\"$APPDIR\")\n}","typeGuard":"fn valid_binary_target(t: &str) -> Option<&str> {\n    if t.contains(\"$APPDIR\") && !t.starts_with(\"$APPDIR/\") { None } else { Some(t) }\n}","tryCatchPattern":"match binary_target_path(target_name, &appdir) {\n    Ok(path) => use(path),\n    Err(e) if e.to_string().contains(\"$APPDIR must prefix\") => fix_target_prefix(target_name),\n    Err(e) => return Err(e),\n}","preventionTips":["Only ever write `$APPDIR/` as the leading prefix of a target name","Lint cask formulas for `$APPDIR` occurrences not at position 0","Copy target strings verbatim from working casks instead of rearranging them"],"tags":["path-validation","brew-cask","invalid-argument-format"],"backgroundTag":"invalid-argument-format","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"}