{"record":{"id":"b49b2518948eaef9","repo":"xai-org/grok-build","slug":"image-clipboard-not-supported-on-this-platform","errorCode":null,"errorMessage":"image clipboard not supported on this platform","messagePattern":"image clipboard not supported on this platform","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-grok-shared/src/clipboard.rs","lineNumber":2181,"sourceCode":"                            \"CLI image clipboard write failed ({spec_name}): {e}\",\n                            spec_name = spec.name\n                        );\n                        last_err = Some(e);\n                    }\n                }\n            }\n            if any_ok {\n                return Ok(());\n            }\n            if let Some(e) = last_err {\n                return Err(e);\n            }\n            anyhow::bail!(\"no CLI tool supports image clipboard writes\");\n        }\n        #[cfg(not(target_os = \"linux\"))]\n        {\n            let _ = path;\n            anyhow::bail!(\"image clipboard not supported on this platform\")\n        }\n    }\n\n    /// Encode raw RGBA pixels into PNG bytes.\n    pub(super) fn encode_rgba_to_png(\n        rgba: &[u8],\n        width: u32,\n        height: u32,\n    ) -> anyhow::Result<Vec<u8>> {\n        use image::codecs::png::PngEncoder;\n        use image::{ColorType, ImageEncoder};\n\n        let expected_len = (width as usize) * (height as usize) * 4;\n        if rgba.len() < expected_len {\n            anyhow::bail!(\n                \"RGBA buffer too short: expected at least {} bytes for {}x{}, got {}\",\n                expected_len,\n                width,","sourceCodeStart":2163,"sourceCodeEnd":2199,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-grok-shared/src/clipboard.rs#L2163-L2199","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Guard the call with #[cfg(target_os = \"linux\")] or a runtime OS check and skip/degrade gracefully on other platforms.","Implement a platform backend (macOS: osascript/NSPasteboard, Windows: clipboard-win) and replace the cfg(not(...)) bail branch.","Fall back to writing the PNG to a temp file and informing the user instead of copying to the clipboard."],"exampleFix":"// before\nclipboard::copy_image(&png_bytes)?;\n// after\n#[cfg(target_os = \"linux\")]\nclipboard::copy_image(&png_bytes)?;\n#[cfg(not(target_os = \"linux\"))]\neprintln!(\"image clipboard unsupported on this platform; saved to file instead\");","handlingStrategy":"fallback","validationCode":"// compile-time gate\n#[cfg(target_os = \"linux\")]\nfn clipboard_image_supported() -> bool { true }\n#[cfg(not(target_os = \"linux\"))]\nfn clipboard_image_supported() -> bool { false }","typeGuard":null,"tryCatchPattern":"match clipboard::copy_image(&png) {\n    Ok(()) => {},\n    Err(e) if e.to_string().contains(\"not supported on this platform\") => {\n        // fallback: write to temp file\n        std::fs::write(\"/tmp/image.png\", &png)?;\n        eprintln!(\"clipboard unavailable; image saved to /tmp/image.png\");\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Gate all clipboard image code behind #[cfg(target_os = \"linux\")] or a runtime feature check","Document platform support in the API so callers can branch before calling","Always provide a file-based fallback path for image export"],"tags":["clipboard","platform-support","linux-only","compile-time-cfg"],"backgroundTag":"clipboard-unsupported-platform","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}