BigPizzaV3/CodexPlusPlus · error · anyhow::Error

打开 DMG 失败:{error}

Error message

打开 DMG 失败:{error}

What it means

On macOS, launch_installer runs Command::new("open").arg(path) to mount the DMG; "打开 DMG 失败:{error}" wraps a failure to spawn the open command itself. Because the binary is resolved via PATH, the realistic trigger is a sanitized environment (the app launched without a standard PATH that includes /usr/bin) or a system policy blocking process spawning. Only spawn failure is reported — whether the DMG actually mounted is not awaited.

Source

Thrown at crates/codex-plus-core/src/update.rs:427

pub fn launch_installer(path: &Path) -> anyhow::Result<()> {
    #[cfg(windows)]
    {
        use std::os::windows::process::CommandExt;
        std::process::Command::new(path)
            .creation_flags(crate::windows_integration::CREATE_NO_WINDOW)
            .spawn()
            .map(|_| ())
            .map_err(|error| anyhow::anyhow!("启动安装包失败:{error}"))
    }

    #[cfg(target_os = "macos")]
    {
        std::process::Command::new("open")
            .arg(path)
            .spawn()
            .map(|_| ())
            .map_err(|error| anyhow::anyhow!("打开 DMG 失败:{error}"))
    }

    #[cfg(all(not(windows), not(target_os = "macos")))]
    {
        let _ = path;
        anyhow::bail!("当前平台不支持启动安装包")
    }
}

View on GitHub (pinned to 1f431ae49b)

Solutions

  1. Ensure the process environment has a sane PATH (at minimum /usr/bin) before launching
  2. If you maintain the crate, resolve open by absolute path (/usr/bin/open) instead of PATH lookup
  3. Verify the DMG path exists before launching
  4. If policy restricts spawning, mount the DMG from a helper that is allowed to spawn processes

Example fix

// before (library-internal)
std::process::Command::new("open").arg(path).spawn()

// after
std::process::Command::new("/usr/bin/open").arg(path).spawn()
Defensive patterns

Strategy: try-catch

Try / catch

match launch_installer(&install.installer_path) {
    Ok(()) => { /* spawned */ }
    Err(err) if err.to_string().contains("打开 DMG 失败") => {
        // inspect PATH in this process; if /usr/bin is missing, re-spawn with a fixed PATH env
    }
    Err(err) => return Err(err),
}

Prevention

When it happens

Trigger: The manager app is started by a launcher/daemon with a scrubbed environment so PATH does not include /usr/bin; the open binary is missing; hardened-runtime/sandbox policy denies spawning.

Common situations: Apps started by launchd/supervisord-style wrappers with minimal environments; sandboxed or policy-restricted macOS setups; CI contexts calling launch_installer without a normal user session.

Related errors


AI-assisted analysis of BigPizzaV3/CodexPlusPlus@1f431ae49b (2026-08-16). Data as JSON: /api/errors/5603e8e0eb0abdd5. Report an issue: GitHub.