{"record":{"id":"8060971c205cd446","repo":"xai-org/grok-build","slug":"pbcopy-exited-with-status-status","errorCode":null,"errorMessage":"pbcopy exited with status {status}","messagePattern":"pbcopy exited with status (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-grok-shared/src/clipboard.rs","lineNumber":1018,"sourceCode":"            ..Default::default()\n        };\n        let result = (|| -> anyhow::Result<()> {\n            // Spooled stdin (not a pipe): a stalled pbcopy must not block the\n            // UI thread on the write, and the deadline wait needs stdin closed.\n            let stdin = super::spool_for_stdin(text.as_bytes())?;\n            let mut cmd = Command::new(\"pbcopy\");\n            cmd.stdin(Stdio::from(stdin))\n                .stdout(Stdio::null())\n                .stderr(Stdio::null());\n            xai_grok_tools::util::detach_std_command(&mut cmd);\n            #[allow(clippy::disallowed_methods)] // short-lived clipboard helper, waited on below\n            let mut child = cmd\n                .spawn()\n                .map_err(|e| anyhow::anyhow!(\"failed to spawn pbcopy: {e}\"))?;\n            let deadline = std::time::Duration::from_secs(2);\n            let status = super::wait_with_deadline(&mut child, deadline)?;\n            if !status.success() {\n                anyhow::bail!(\"pbcopy exited with status {status}\");\n            }\n            Ok(())\n        })();\n        match result {\n            Ok(()) => {\n                outcome.cli_ok = true;\n                outcome.cli_ok_tools.push(\"pbcopy\");\n                outcome.any_ok = true;\n            }\n            Err(e) => tracing::debug!(\"pbcopy failed: {e}\"),\n        }\n        outcome\n    }\n\n    /// Read an image from the macOS clipboard via `osascript`.\n    ///\n    /// Probes PNG, TIFF, then JPEG in a single `osascript` invocation\n    /// using nested `try` blocks. This avoids spawning up to 3 separate","sourceCodeStart":1000,"sourceCodeEnd":1036,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-grok-shared/src/clipboard.rs#L1000-L1036","documentation":"On the macOS pbcopy write leg, if the spawned pbcopy process finishes with a non-zero exit status after the 2-second deadline wait, the leg reports failure with this message. It distinguishes 'pbcopy ran but failed' from spawn failures or timeouts.","triggerScenarios":"Calling set_text on macOS when pbcopy starts but exits non-zero — typically because the pasteboard is unavailable in the session (SSH without a proper launchd user session, sandbox restrictions).","commonSituations":"SSH sessions on macOS where the launchd context lacks a clipboard; automation tools running pbcopy under restricted contexts; full pasteboard daemon issues.","solutions":["Check whether the environment has access to the macOS user pasteboard (run `echo hi | pbcopy && pbpaste` manually)","Run inside a regular graphical/login session rather than an SSH or restricted context","Rely on the arboard leg, which set_text attempts alongside pbcopy, or fix the session so it works","Inspect the reported status code for the specific pbcopy failure"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Confirm pbcopy works in the current session\nlet ok = std::process::Command::new(\"sh\")\n    .arg(\"-c\").arg(\"echo test | pbcopy && [ \\\"$(pbpaste)\\\" = test ]\")\n    .status().map(|s| s.success()).unwrap_or(false);","typeGuard":null,"tryCatchPattern":"match clipboard::set_text(&text) {\n    Err(e) if e.to_string().contains(\"pbcopy exited with status\") => {\n        eprintln!(\"pbcopy failed ({e}); trying alternate backend\");\n        // fall back to arboard-based path or manual instructions\n    }\n    other => other?,\n}","preventionTips":["Run inside a regular macOS login/graphical session, not a bare SSH context","Smoke-test `echo hi | pbcopy` in the target environment before deploying","Keep the arboard leg enabled so set_text has a second chance","Check pasteboard daemon health if failures persist"],"tags":["clipboard","macos","process"],"backgroundTag":"clipboard-command-failed","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}