xai-org/grok-build · error

failed to read clipboard temp file: {e}

Error message

failed to read clipboard temp file: {e}

What it means

read_clipboard_image_from_class (crates/codegen/xai-grok-shared/src/clipboard.rs:820) dumps the clipboard image to a temp file and reads it back; if std::fs::read fails it returns this error after cleaning up the temp file. The clipboard access itself succeeded — the failure is in filesystem I/O on the temp path.

Source

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

        path_tiff: &std::path::Path,
        path_jpg: &std::path::Path,
    ) -> anyhow::Result<Option<ImageData>> {
        let (temp_path, mime) = match class {
            "PNGf" => (path_png, "image/png"),
            "TIFF" => (path_tiff, "image/tiff"),
            "JPEG" => (path_jpg, "image/jpeg"),
            _ => return Ok(None),
        };

        let data = match std::fs::read(temp_path) {
            Ok(bytes) if !bytes.is_empty() => bytes,
            Ok(_) => {
                let _ = std::fs::remove_file(temp_path);
                return Ok(None);
            }
            Err(e) => {
                let _ = std::fs::remove_file(temp_path);
                return Err(anyhow::anyhow!("failed to read clipboard temp file: {e}"));
            }
        };

        let _ = std::fs::remove_file(temp_path);
        Ok(Some(ImageData {
            data,
            mime_type: mime.to_owned(),
        }))
    }

    fn remove_attachment_probe_temps(
        path_png: &std::path::Path,
        path_tiff: &std::path::Path,
        path_jpg: &std::path::Path,
    ) {
        let _ = std::fs::remove_file(path_png);
        let _ = std::fs::remove_file(path_tiff);
        let _ = std::fs::remove_file(path_jpg);

View on GitHub (pinned to bc7f02eddd)

Solutions

  1. Check TMPDIR points to an existing, writable directory (`ls -ld $TMPDIR /tmp`).
  2. Rule out external cleaners (systemd-tmpfiles, antivirus) deleting the file mid-flight.
  3. Ensure no concurrent processes share/collide on the same temp file path.
  4. Free disk space if the filesystem is full.
Defensive patterns

Strategy: try-catch

Validate before calling

fn temp_dir_writable() -> bool {
    std::env::temp_dir().metadata().map(|m| m.is_dir()).unwrap_or(false)
}

Try / catch

match get_image() {
    Err(e) if e.to_string().contains("failed to read clipboard temp file") => {
        eprintln!("temp file I/O problem: {e}");
        Ok(None)
    }
    other => other,
}

Prevention

When it happens

Trigger: get_image / get_attachments on Linux (X11 class-based read) where the temp file was deleted concurrently, the temp dir is unwritable/read-protected, or the disk is full between write and read.

Common situations: See trigger scenarios.

Related errors


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