{"record":{"id":"baca2d9b39c33267","repo":"Hmbown/CodeWhale","slug":"failed-to-write-to-label-e","errorCode":null,"errorMessage":"Failed to write to {label}: {e}","messagePattern":"Failed to write to (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/tui/clipboard.rs","lineNumber":696,"sourceCode":"\n#[cfg(all(any(target_os = \"macos\", target_os = \"windows\"), not(test)))]\nfn write_text_with_stdin_command(\n    program: &str,\n    args: &[&str],\n    text: &str,\n    label: &str,\n) -> Result<()> {\n    let mut child = Command::new(program)\n        .args(args)\n        .stdin(Stdio::piped())\n        .stdout(Stdio::null())\n        .stderr(Stdio::null())\n        .spawn()\n        .map_err(|e| anyhow::anyhow!(\"Failed to run {label}: {e}\"))?;\n    if let Some(mut stdin) = child.stdin.take() {\n        stdin\n            .write_all(text.as_bytes())\n            .map_err(|e| anyhow::anyhow!(\"Failed to write to {label}: {e}\"))?;\n    }\n    let _ = std::thread::Builder::new()\n        .name(\"clipboard-wait\".to_string())\n        .spawn(move || {\n            let _ = child.wait();\n        });\n    Ok(())\n}\n\n#[cfg(all(target_os = \"linux\", not(target_env = \"ohos\"), not(test)))]\nfn write_text_with_wlcopy(text: &str) -> Result<()> {\n    write_text_with_wlcopy_using_argv(\"wl-copy\", text)\n}\n\n#[cfg(all(target_os = \"linux\", not(target_env = \"ohos\"), not(test)))]\nfn read_text_with_wlpaste() -> Result<String> {\n    read_text_with_wlpaste_using_argv(\"wl-paste\")\n}","sourceCodeStart":678,"sourceCodeEnd":714,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/crates/tui/src/tui/clipboard.rs#L678-L714","documentation":"This error is thrown by write_text_with_stdin_command in crates/tui/src/tui/clipboard.rs when writing the clipboard text to the spawned clipboard helper's (e.g. pbcopy, set-clipboard) stdin pipe fails. The library spawns the helper and pipes the text in; any I/O error on that pipe (broken pipe, closed fd, EINTR exhaustion) is wrapped with this message. It means the text never reached the clipboard helper.","triggerScenarios":"Calling write_text_with_pbcopy or write_text_with_set_clipboard when the child process exits before consuming the text (e.g. the helper crashed or was killed), the pipe fd was closed, or a transient EINTR/partial-write condition occurs during stdin.write_all.","commonSituations":"macOS pbcopy killed by the environment or sandbox; SSH session where the clipboard daemon died; helper binary present at spawn but crashing on startup while large text is still being written (classic EPIPE); resource limits closing descriptors.","solutions":["Retry the clipboard write; transient EPIPE/partial writes are often one-shot.","Verify the helper binary (pbcopy / set-clipboard) actually runs standalone: echo hi | pbcopy.","Check clipboard size — very large text increases the chance the child exits before reading; reduce or chunk the payload.","Fall back to another clipboard backend (the library's other write_text_with_* strategies).","Confirm no sandbox/seccomp profile is killing spawned children mid-run."],"exampleFix":"// before\nstdin.write_all(text.as_bytes()).map_err(|e| anyhow::anyhow!(\"Failed to write to {label}: {e}\"))?;\n// after\nmatch stdin.write_all(text.as_bytes()) {\n    Ok(()) => {}\n    Err(e) if e.kind() == std::io::ErrorKind::BrokenPipe => {\n        return write_text_fallback(text); // try next backend\n    }\n    Err(e) => return Err(anyhow::anyhow!(\"Failed to write to {label}: {e}\")),\n}","handlingStrategy":"fallback","validationCode":"// before writing: ensure the helper can run and accept stdin\nlet ok = Command::new(\"pbcopy\").arg(\"-help\").stdin(Stdio::null()).stdout(Stdio::null()).stderr(Stdio::null()).status().map(|s| s.success()).unwrap_or(false);\nif !ok { eprintln!(\"clipboard helper unavailable; using fallback\"); }","typeGuard":null,"tryCatchPattern":"match write_text_with_pbcopy(text) {\n    Err(e) if e.to_string().contains(\"Failed to write\") => {\n        // child died mid-write (broken pipe) — try next backend\n        write_text_with_osc52(text).unwrap_or_else(|e2| eprintln!(\"clipboard write failed: {e2:#}\"));\n    }\n    Err(e) => eprintln!(\"clipboard write failed: {e:#}\"),\n    Ok(()) => {}\n}","preventionTips":["Check the helper binary exists and runs before choosing the backend.","Keep clipboard payloads moderate; huge writes increase broken-pipe odds.","Prefer falling back across the library's backends instead of propagating one helper's I/O error.","Ensure no sandbox kills spawned children mid-write."],"tags":["clipboard","process","io","broken-pipe"],"backgroundTag":"broken-pipe","analyzedSha":"433685b2024e7bc4c99e1e2e326bcad39b4d9d65","analyzedAt":"2026-09-15T12:24:24.634Z","contentChangedAt":"2026-09-15T12:24:24.634Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}