jdx/mise · error
brew-cask: $APPDIR must prefix a binary target
Error message
brew-cask: $APPDIR must prefix a binary target
What it means
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.
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`)
Example fix
// before
binary_target_path("bin/$APPDIR/mytool", &appdir)
// error: brew-cask: $APPDIR must prefix a binary target
// after
binary_target_path("$APPDIR/mytool", &appdir) Defensive patterns
Strategy: validation
Validate before calling
fn appdir_target_is_valid(target: &str) -> bool {
target.starts_with("$APPDIR/") || !target.contains("$APPDIR")
} Type guard
fn valid_binary_target(t: &str) -> Option<&str> {
if t.contains("$APPDIR") && !t.starts_with("$APPDIR/") { None } else { Some(t) }
} Try / catch
match binary_target_path(target_name, &appdir) {
Ok(path) => use(path),
Err(e) if e.to_string().contains("$APPDIR must prefix") => fix_target_prefix(target_name),
Err(e) => return Err(e),
} Prevention
- 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
When it happens
Trigger: 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`.
Common situations: 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.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- brew-cask: ' ' must be an absolute path
- brew-cask: ' ' must not resolve to the filesystem root
- brew-cask: app target contains NUL
- brew-cask: app target
- brew-cask: app target
AI-assisted analysis of jdx/mise@533346cc37 (2026-09-17).
Data as JSON: /api/errors/5e8809048b7df93d.
Report an issue: GitHub.
Appendix: source
Thrown at src/system/packages/brew/cask/paths.rs:281
.map(|root| root.display().to_string())
.collect::<Vec<_>>()
.join(" or ")
}
pub(super) fn binary_target_path(target_name: &str, appdir: &Path) -> Result<PathBuf> {
if target_name.contains('\0') {
bail!("brew-cask: binary target contains NUL");
}
if let Some(relative) = target_name.strip_prefix("$APPDIR/") {
let relative = Path::new(relative);
reject_appdir_escape(relative, "binary $APPDIR target", target_name)?;
if !allowed_appdir_roots()?.iter().any(|root| root == appdir) {
bail!("brew-cask: invalid appdir '{}'", appdir.display());
}
return Ok(appdir.join(relative));
}
if target_name.contains("$APPDIR") {
bail!("brew-cask: $APPDIR must prefix a binary target");
}
let prefix = prefix::prefix();
let prefix_str = prefix.to_string_lossy();
let target_name = target_name.replace("$HOMEBREW_PREFIX", prefix_str.as_ref());
let path = PathBuf::from(&target_name);
let target = if path.is_absolute() {
path
} else if target_name.contains('/') {
prefix.join(path)
} else {
prefix.join("bin").join(path)
};
if target
.components()
.any(|component| matches!(component, Component::ParentDir))
{
bail!(
"brew-cask: binary target '{}' must not contain '..'",View on GitHub (pinned to 533346cc37)