jdx/mise · error

brew-cask: invalid font target

Error message

brew-cask: invalid font target '{}'

What it means

font_target_path computes where a font is linked: font_dir().join(name), where name comes from font_filename (the font's explicit target or its source filename). The name must be relative, non-empty, and contain no ParentDir component — otherwise the link would escape the platform font directory (~/.local/share/fonts on Linux, ~/Library/Fonts on macOS). Any violation bails with the computed name.

Solutions

  1. Set the font target to a bare filename ("Foo.ttf") or a simple relative subpath
  2. Omit the target so the name is derived from the source file
  3. Strip any leading '/' or '..' from the stanza

Example fix

# before (cask stanza)
font "FiraCode.ttf", target: "/Library/Fonts/FiraCode.ttf"

# after
font "FiraCode.ttf"
Defensive patterns

Strategy: validation

Validate before calling

// Validate the computed font filename before install.
fn valid_font_name(name: &str) -> bool {
    let p = Path::new(name);
    !p.is_absolute()
        && p.components().next().is_some()
        && !p.components().any(|c| matches!(c, std::path::Component::ParentDir))
}

Type guard

fn is_bare_font_filename(target: Option<&str>) -> bool {
    target.map(valid_font_name).unwrap_or(true)
}

Prevention

When it happens

Trigger: font target: "/Library/Fonts/X.ttf" (absolute), "../X.ttf", an empty target with an unnameable source, or any target containing '..' segments.

Common situations: Cask authors copying Homebrew ruby syntax that tolerated absolute font targets; templating bugs producing empty or traversal-laden strings.

Related errors


AI-assisted analysis of jdx/mise@6f52dcdf99 (2026-08-22). Data as JSON: /api/errors/3a7706c610ed3763. Report an issue: GitHub.

Appendix: source

Thrown at src/system/packages/brew/cask.rs:2904

            .filter(|entry| entry.file_type().is_ok_and(|ft| ft.is_dir()))
            .any(|entry| relative.is_some_and(|path| entry.path().join(path).is_file()));
        if has_staged_copy {
            file::remove_file(target)?;
        }
    }
    Ok(())
}

fn font_target_path(font: &FontArtifact) -> Result<PathBuf> {
    let name = font_filename(font)?;
    let name_path = Path::new(&name);
    if name_path.is_absolute()
        || name_path
            .components()
            .any(|component| matches!(component, Component::ParentDir))
        || name_path.components().next().is_none()
    {
        bail!("brew-cask: invalid font target '{}'", name);
    }
    Ok(font_dir().join(name_path))
}

fn font_dir() -> PathBuf {
    if cfg!(target_os = "linux") {
        crate::env::XDG_DATA_HOME.join("fonts")
    } else {
        crate::dirs::HOME.join("Library").join("Fonts")
    }
}

#[cfg(test)]
fn execute_flight_steps(
    cask: &Cask,
    steps: &[FlightStep],
    staged_path: &Path,
    appdir: &Path,

View on GitHub (pinned to 6f52dcdf99)