xai-org/grok-build · error

failed to run {label}: {error}

Error message

failed to run {label}: {error}

What it means

checked_command_stdout in crates/codegen/xai-grok-shared/src/clipboard.rs:781 wraps the std::io::Result of running a macOS clipboard command (pbpaste/osascript) and fails with this message when the process could not be launched at all. A non-zero exit is reported separately, so this error specifically means spawn/exec failed (typically binary not found).

Source

Thrown at crates/codegen/xai-grok-shared/src/clipboard.rs:781

            let mut buf = vec![0u8; len];
            // SAFETY: source is valid for `len` reads (NSData contract),
            // destination is a fresh Vec of exactly `len` bytes, and the
            // regions cannot overlap.
            unsafe {
                std::ptr::copy_nonoverlapping(bytes_ptr as *const u8, buf.as_mut_ptr(), len);
            }
            Some(super::ImageData {
                data: buf,
                mime_type: mime.to_owned(),
            })
        })
    }

    pub(super) fn checked_command_stdout(
        label: &str,
        output: std::io::Result<std::process::Output>,
    ) -> anyhow::Result<Vec<u8>> {
        let output = output.map_err(|error| anyhow::anyhow!("failed to run {label}: {error}"))?;
        if !output.status.success() {
            let stderr = String::from_utf8_lossy(&output.stderr);
            anyhow::bail!("{label} exited with {}: {}", output.status, stderr.trim());
        }
        Ok(output.stdout)
    }

    fn attachments_probe_temp_paths() -> (std::path::PathBuf, std::path::PathBuf, std::path::PathBuf)
    {
        let temp_dir = std::env::temp_dir();
        (
            temp_dir.join("grok-clipboard-probe.png"),
            temp_dir.join("grok-clipboard-probe.tiff"),
            temp_dir.join("grok-clipboard-probe.jpg"),
        )
    }

    fn read_clipboard_image_from_class(

View on GitHub (pinned to bc7f02eddd)

Solutions

  1. Verify the tool (pbpaste/osascript/pbcopy) exists: `which <tool>`; install it or run on macOS.
  2. Fix PATH for the environment running the process so the system binary dir is included.
  3. Fall back to an alternate clipboard backend (e.g. arboard) when the OS tool is unavailable.

Example fix

// before
let bytes = checked_command_stdout("pbpaste", Command::new("pbpaste").output())?;
// after
match checked_command_stdout("pbpaste", Command::new("pbpaste").output()) {
    Ok(bytes) => bytes,
    Err(e) => return fallback_backend().map_err(|_| e),
}
Defensive patterns

Strategy: fallback

Validate before calling

fn tool_available(bin: &str) -> bool {
    std::process::Command::new(bin).arg("--help").output().is_ok()
}

Try / catch

match get_text() {
    Err(e) if e.to_string().starts_with("failed to run ") => fallback_backend(),
    other => other,
}

Prevention

When it happens

Trigger: get_text, get_image, or run_attachments_osascript invoking a command whose binary is missing from PATH or not executable — e.g. pbpaste/osascript absent on Linux.

Common situations: Running macOS-targeted clipboard code on Linux/CI containers; minimal Docker images without macOS system tools; stripped PATH in systemd/IDE-launched processes.

Related errors


AI-assisted analysis of xai-org/grok-build@bc7f02eddd (2026-08-31). Data as JSON: /api/errors/f06be376e31d6c58. Report an issue: GitHub.