{"record":{"id":"d2ffc8f6d8f9df67","repo":"Hmbown/CodeWhale","slug":"failed-to-wait-on-program-e","errorCode":null,"errorMessage":"Failed to wait on {program}: {e}","messagePattern":"Failed to wait on (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/tui/src/tui/clipboard.rs","lineNumber":748,"sourceCode":"}\n\n#[cfg(all(target_os = \"linux\", not(target_env = \"ohos\"), not(test)))]\nfn write_text_with_wlcopy_using_argv(program: &str, text: &str) -> Result<()> {\n    let mut child = Command::new(program)\n        .stdin(Stdio::piped())\n        .stdout(Stdio::null())\n        .stderr(Stdio::null())\n        .spawn()\n        .map_err(|e| anyhow::anyhow!(\"Failed to run {program}: {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 {program}: {e}\"))?;\n    }\n    // stdin is dropped here, closing the pipe so wl-copy flushes.\n    let status = child\n        .wait()\n        .map_err(|e| anyhow::anyhow!(\"Failed to wait on {program}: {e}\"))?;\n    if !status.success() {\n        bail!(\"{program} exited with {status}\");\n    }\n    Ok(())\n}\n\n#[cfg(not(test))]\nfn write_text_to_terminal_client(text: &str, in_tmux: bool) -> Result<()> {\n    if in_tmux {\n        return write_text_with_tmux(text);\n    }\n    write_text_with_osc52(text)\n}\n\n#[cfg(not(test))]\nfn write_text_with_tmux(text: &str) -> Result<()> {\n    write_text_with_tmux_using_argv(\"tmux\", &[], text)\n}","sourceCodeStart":730,"sourceCodeEnd":766,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/crates/tui/src/tui/clipboard.rs#L730-L766","documentation":"write_text_with_wlcopy_using_argv throws this when child.wait() on the wl-copy process fails, i.e. the library could not reap the child's exit status. This is rare — it indicates an OS-level error collecting the process (e.g. the child was already reaped or an interrupted/wait syscall error), not a non-zero exit code, which is reported separately via '{program} exited with {status}'.","triggerScenarios":"Calling write_text_with_wlcopy when waitpid on the spawned wl-copy child fails — the child was reaped by another thread (see the detached 'clipboard-wait' pattern used elsewhere in this file) or a low-level wait error (EINTR surfaces in some implementations).","commonSituations":"Custom code elsewhere in the app reaps children (Child::try_wait/wait raced); exotic sandbox environments where wait is restricted; heavily loaded systems with fork/wait resource exhaustion.","solutions":["Check for other code paths or threads that wait()/reap the same Child before this call — double-reap is the usual cause.","Retry the clipboard write once; transient wait errors often clear.","Verify wl-copy completes normally standalone (echo hi | wl-copy; echo $?).","Avoid mixing the detached clipboard-wait thread pattern with a synchronous wait() on the same child.","If sandboxed, confirm waitpid is permitted for spawned children."],"exampleFix":"// before\nlet status = child.wait().map_err(|e| anyhow::anyhow!(\"Failed to wait on {program}: {e}\"))?;\n// after\nlet status = match child.wait() {\n    Ok(s) => s,\n    Err(e) => return Err(anyhow::anyhow!(\"wl-copy could not be reaped ({e}); clipboard result unknown\")),\n};","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match write_text_with_wlcopy(text) {\n    Err(e) if e.to_string().contains(\"Failed to wait\") => {\n        // reaped elsewhere or transient wait failure: result unknown, warn and continue\n        eprintln!(\"clipboard write status unknown: {e:#}\");\n    }\n    Err(e) => return Err(e),\n    Ok(()) => {}\n}","preventionTips":["Do not reap the same Child from another thread; either wait synchronously or delegate fully.","Keep one ownership path per spawned clipboard process.","Treat wait failures as 'status unknown' — the write may have succeeded.","Retry the operation if clipboard content verification matters."],"tags":["clipboard","process","wait","wayland"],"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"}