BigPizzaV3/CodexPlusPlus · error · anyhow::Error

macOS bundle binary points to a shell script

Error message

macOS bundle binary points to a shell script: {}

What it means

validate_binary_source reads the first two bytes of the bundle binary and bails if they are "#!", i.e. the path is a shell script rather than a Mach-O executable. Bundles must embed a real native binary; a wrapper script breaks Launch Services signing/launching, so install is refused early.

Solutions

  1. Point the install at the native Mach-O binary, not the wrapper script
  2. Rebuild the Rust binary with cargo so a real executable is produced
  3. Check `file <path>` — output must be Mach-O, not 'script text executable'
  4. If a wrapper is needed, embed the real binary in the bundle and keep scripts outside Contents/MacOS

Example fix

// before
binary: "/opt/tools/codex-plus-launcher.sh"
// after
binary: "/opt/tools/target/release/codex-plus"
Defensive patterns

Strategy: validation

Validate before calling

let mut head = [0u8; 2];
let n = std::fs::File::open(&path)?.read(&mut head)?;
if n == 2 && &head == b"#!" {
    return Err(format!("{} is a script, not a native binary", path.display()));
}

Type guard

fn is_native_binary(p: &Path) -> bool {
    let mut h = [0u8; 2];
    std::fs::File::open(p)
        .and_then(|mut f| std::io::Read::read(&mut f, &mut h))
        .map(|n| !(n == 2 && &h == b"#!"))
        .unwrap_or(false)
}

Prevention

When it happens

Trigger: write_bundle -> validate_binary_source on macOS when the source file starts with the shebang magic b"#!".

Common situations: Repos that ship a launcher shell script named like the binary; build systems placing a wrapper script instead of the compiled binary; users pointing the install at a dev helper script; post-download scripts replaced by text stubs.

Understand the failure class

Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.

Related errors


AI-assisted analysis of BigPizzaV3/CodexPlusPlus@b1ed92e5e4 (2026-09-19). Data as JSON: /api/errors/442c50b2f8a4545f. Report an issue: GitHub.

Appendix: source

Thrown at crates/codex-plus-core/src/install/macos.rs:164

    if !metadata.is_file() {
        anyhow::bail!(
            "macOS bundle binary is not a regular file: {}",
            path.display()
        );
    }
    if metadata.len() < 1024 {
        anyhow::bail!(
            "macOS bundle binary is unexpectedly small: {}",
            path.display()
        );
    }
    let mut header = [0_u8; 2];
    let mut file = fs::File::open(path)?;
    use std::io::Read;
    let read = file.read(&mut header)?;
    if read == header.len() && header == *b"#!" {
        anyhow::bail!(
            "macOS bundle binary points to a shell script: {}",
            path.display()
        );
    }
    Ok(())
}

#[cfg(target_os = "macos")]
fn copy_icon(resources: &Path) -> anyhow::Result<()> {
    let source = std::env::current_exe()
        .ok()
        .and_then(|path| path.parent().map(Path::to_path_buf))
        .map(|path| path.join("codex-plus-plus.png"));
    if let Some(source) = source.filter(|path| path.exists()) {
        fs::copy(source, resources.join("codex-plus-plus.png"))?;
    }
    Ok(())
}

View on GitHub (pinned to b1ed92e5e4)