xai-org/grok-build · error

image clipboard not supported on this platform

Error message

image clipboard not supported on this platform

What it means

The clipboard image-write helper only implements Linux (via CLI tools like xclip/wl-copy); on every other target OS it unconditionally fails with this bail. The library intentionally refuses to guess platform-specific clipboard APIs, so image clipboard writes are Linux-only by design.

Source

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

                            "CLI image clipboard write failed ({spec_name}): {e}",
                            spec_name = spec.name
                        );
                        last_err = Some(e);
                    }
                }
            }
            if any_ok {
                return Ok(());
            }
            if let Some(e) = last_err {
                return Err(e);
            }
            anyhow::bail!("no CLI tool supports image clipboard writes");
        }
        #[cfg(not(target_os = "linux"))]
        {
            let _ = path;
            anyhow::bail!("image clipboard not supported on this platform")
        }
    }

    /// Encode raw RGBA pixels into PNG bytes.
    pub(super) fn encode_rgba_to_png(
        rgba: &[u8],
        width: u32,
        height: u32,
    ) -> anyhow::Result<Vec<u8>> {
        use image::codecs::png::PngEncoder;
        use image::{ColorType, ImageEncoder};

        let expected_len = (width as usize) * (height as usize) * 4;
        if rgba.len() < expected_len {
            anyhow::bail!(
                "RGBA buffer too short: expected at least {} bytes for {}x{}, got {}",
                expected_len,
                width,

View on GitHub (pinned to bc7f02eddd)

Solutions

  1. Guard the call with #[cfg(target_os = "linux")] or a runtime OS check and skip/degrade gracefully on other platforms.
  2. Implement a platform backend (macOS: osascript/NSPasteboard, Windows: clipboard-win) and replace the cfg(not(...)) bail branch.
  3. Fall back to writing the PNG to a temp file and informing the user instead of copying to the clipboard.

Example fix

// before
clipboard::copy_image(&png_bytes)?;
// after
#[cfg(target_os = "linux")]
clipboard::copy_image(&png_bytes)?;
#[cfg(not(target_os = "linux"))]
eprintln!("image clipboard unsupported on this platform; saved to file instead");
Defensive patterns

Strategy: fallback

Validate before calling

// compile-time gate
#[cfg(target_os = "linux")]
fn clipboard_image_supported() -> bool { true }
#[cfg(not(target_os = "linux"))]
fn clipboard_image_supported() -> bool { false }

Try / catch

match clipboard::copy_image(&png) {
    Ok(()) => {},
    Err(e) if e.to_string().contains("not supported on this platform") => {
        // fallback: write to temp file
        std::fs::write("/tmp/image.png", &png)?;
        eprintln!("clipboard unavailable; image saved to /tmp/image.png");
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Calling the image clipboard write function (which encode_rgba_to_png feeds) compiled for any target_os other than linux, e.g. macOS or Windows builds; the cfg(not(target_os = "linux")) branch always bails with this message.

Common situations: Running a screenshot/copy-image feature on macOS or Windows builds; cross-platform code that assumes clipboard image support exists everywhere; CI on non-Linux runners exercising the clipboard path.

Related errors


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