Hmbown/CodeWhale · warning
Failed to wait on
Error message
Failed to wait on {program}: {e} What it means
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}'.
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.
Example fix
// before
let status = child.wait().map_err(|e| anyhow::anyhow!("Failed to wait on {program}: {e}"))?;
// after
let status = match child.wait() {
Ok(s) => s,
Err(e) => return Err(anyhow::anyhow!("wl-copy could not be reaped ({e}); clipboard result unknown")),
}; Defensive patterns
Strategy: try-catch
Try / catch
match write_text_with_wlcopy(text) {
Err(e) if e.to_string().contains("Failed to wait") => {
// reaped elsewhere or transient wait failure: result unknown, warn and continue
eprintln!("clipboard write status unknown: {e:#}");
}
Err(e) => return Err(e),
Ok(()) => {}
} Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- Failed to write to
- clipboard read failed
- Failed to run
- Failed to write to
- PRIMARY selection busy or unavailable
AI-assisted analysis of Hmbown/CodeWhale@433685b202 (2026-09-15).
Data as JSON: /api/errors/d2ffc8f6d8f9df67.
Report an issue: GitHub.
Appendix: source
Thrown at crates/tui/src/tui/clipboard.rs:748
}
#[cfg(all(target_os = "linux", not(target_env = "ohos"), not(test)))]
fn write_text_with_wlcopy_using_argv(program: &str, text: &str) -> Result<()> {
let mut child = Command::new(program)
.stdin(Stdio::piped())
.stdout(Stdio::null())
.stderr(Stdio::null())
.spawn()
.map_err(|e| anyhow::anyhow!("Failed to run {program}: {e}"))?;
if let Some(mut stdin) = child.stdin.take() {
stdin
.write_all(text.as_bytes())
.map_err(|e| anyhow::anyhow!("Failed to write to {program}: {e}"))?;
}
// stdin is dropped here, closing the pipe so wl-copy flushes.
let status = child
.wait()
.map_err(|e| anyhow::anyhow!("Failed to wait on {program}: {e}"))?;
if !status.success() {
bail!("{program} exited with {status}");
}
Ok(())
}
#[cfg(not(test))]
fn write_text_to_terminal_client(text: &str, in_tmux: bool) -> Result<()> {
if in_tmux {
return write_text_with_tmux(text);
}
write_text_with_osc52(text)
}
#[cfg(not(test))]
fn write_text_with_tmux(text: &str) -> Result<()> {
write_text_with_tmux_using_argv("tmux", &[], text)
}View on GitHub (pinned to 433685b202)