#1047·navi

navi --print panics when writing to a closed pipe (EPIPE)

Author: MathjkCreated Sep 30, 2026Updated Sep 30, 2026

Describe the bug

navi --print panics when its stdout is a pipe that has already been closed (EPIPE). --print is navi's non-TUI output path, so it's the mode most likely to be piped into other programs — it should tolerate the consumer exiting early.

To Reproduce

On Windows (reproduces 3/3):

cmd
navi.exe --print --best-match --query trivial --path cheats | exit0.exe

where exit0.exe is any program that exits immediately (e.g. navi ... | cmd /c exit 0 has the same race, a closed-pipe helper just makes it deterministic). The same happens on Unix, e.g.:

bash
navi --print --best-match --query trivial --path cheats | head -c 0

Output:

thread 'main' panicked at library\std\src\io\stdio.rs:1118:9:
failed printing to stdout: The pipe is being closed. (os error 232)
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

(on Linux/macOS this is Broken pipe (os error 32) instead)

The panic comes from src/commands/core/actor.rs in actor::act():

rust
Action::Print => {
    println!("{interpolated_snippet}");
}

println! panics when the underlying write fails with io::ErrorKind::BrokenPipe.

Expected behavior

When the consumer of the pipe has gone away, navi should exit quietly (exit code 0) instead of panicking — this is the behaviour of standard Unix tools (cat, ls, fzf --filter, ...), which treat a closed stdout pipe as a normal termination condition.

Versions:

  • OS: Windows 10/11 (also reproducible on Linux)
  • navi: current master (2.24.x, commit 7389f95)

Additional context

The fix is small: write through io::stdout().lock() with writeln! and map ErrorKind::BrokenPipe to a quiet exit instead of letting println! panic. I have a branch ready (fix/epipe-print) and can open a PR if the approach looks good.