{"record":{"id":"947d009771d5fd22","repo":"xai-org/grok-build","slug":"failed-to-spawn-pbcopy-e","errorCode":null,"errorMessage":"failed to spawn pbcopy: {e}","messagePattern":"failed to spawn pbcopy: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-grok-shared/src/clipboard.rs","lineNumber":1014,"sourceCode":"\n    pub fn set_text_with_outcome(text: &str) -> super::NativeWriteOutcome {\n        let mut outcome = super::NativeWriteOutcome {\n            cli_tools_tried: vec![\"pbcopy\"],\n            ..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","sourceCodeStart":996,"sourceCodeEnd":1032,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-grok-shared/src/clipboard.rs#L996-L1032","documentation":"set_text_with_outcome (crates/codegen/xai-grok-shared/src/clipboard.rs:1014) writes text via the macOS `pbcopy` tool; this error wraps the std::io::Error when pbcopy cannot be spawned. It does not indicate pbcopy failed later — a non-zero exit is reported as 'pbcopy exited with status'.","triggerScenarios":"Calling set_text_with_outcome on a system where pbcopy is missing from PATH or not executable (Linux, minimal container, broken PATH).","commonSituations":"Cross-platform apps invoking the macOS path by mistake; headless CI runners; PATH sanitization in daemons dropping /usr/bin.","solutions":["Run on macOS or install/reveal pbcopy; verify with `which pbcopy`.","Fix the process PATH so /usr/bin is present.","Prefer the arboard backend when the platform tool is unavailable."],"exampleFix":"// before\nset_text_with_outcome(text)?;\n// after\nif which(\"pbcopy\").is_none() {\n    arboard_set_text(&text)?;\n} else {\n    set_text_with_outcome(text)?;\n}","handlingStrategy":"fallback","validationCode":"let pbcopy_ok = std::process::Command::new(\"pbcopy\").arg(\"-v\").output().is_ok();","typeGuard":null,"tryCatchPattern":"match set_text_with_outcome(text) {\n    Err(e) if e.to_string().contains(\"failed to spawn pbcopy\") => arboard_set_text(text),\n    other => other,\n}","preventionTips":["Only use the pbcopy path on macOS (`cfg(target_os = \"macos\")` or runtime check).","Verify pbcopy with `which pbcopy` before writing.","Keep an arboard fallback wired in."],"tags":["clipboard","macos","pbcopy","process-spawn"],"backgroundTag":"command-spawn-failed","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}