atuinsh/atuin · error

failed printing to stdout

Error message

failed printing to stdout: {e}

What it means

When Atuin writes the shell init script (e.g. `atuin init bash`) to stdout, a write failure surfaces here. `write!` on a locked stdout returns an error instead of panicking, so the code panics manually to preserve the historic `println!` panic message.

Solutions

  1. Ensure stdout is open and its consumer is still reading
  2. Avoid piping init output into commands that exit early (e.g. `| head`) — use `eval "$(atuin init bash)"` instead
  3. Check disk space if stdout is redirected to a file
  4. Capture the io::Error `{e}` in the panic for the real cause

Example fix

// before
atuin init bash | head -20
// after
eval "$(atuin init bash)"
Defensive patterns

Strategy: try-catch

Try / catch

match std::panic::catch_unwind(|| atuin::command::client::init::bash::init_static(&opts)) {
    Ok(_) => {},
    Err(_) => eprintln!("atuin init failed: stdout not writable"),
}
// or avoid the failure: consume stdout fully instead of piping to early-exiting commands

Prevention

When it happens

Trigger: `atuin init <shell>` (via init_static) when the underlying write to stdout fails — closed stdout, broken pipe, or full disk.

Common situations: Piping `atuin init bash` into `head` or a closed consumer, redirecting stdout to a full filesystem, or a terminal that has gone away.

Related errors


AI-assisted analysis of atuinsh/atuin@900007c480 (2026-09-19). Data as JSON: /api/errors/65aee3b5600a3c7c. Report an issue: GitHub.

Appendix: source

Thrown at crates/atuin/src/command/client/init/bash.rs:53

    write_tmux_config(writer, options.tmux)?;
    writeln!(writer, "__atuin_bind_ctrl_r={bind_ctrl_r}")?;
    writeln!(writer, "__atuin_bind_up_arrow={bind_up_arrow}")?;
    writeln!(writer, "{}", BASH.main)?;

    #[cfg(feature = "ai")]
    if options.enable_ai {
        writeln!(writer, "{}", atuin_ai::shell::BASH_INIT)?;
    }

    writeln!(writer, "}}") // end include guard
}

pub fn init_static(options: &StaticInitOptions<'_>) {
    if let Err(e) = write_static_init(&mut io::stdout().lock(), options) {
        // This function used to use `println!`, which panics on write failure with this same
        // message. Using a locked `Stdout` object is faster, but `write!` returns an error rather
        // than panicking, so we manually panic here to keep the same behavior.
        panic!("failed printing to stdout: {e}");
    }
}

View on GitHub (pinned to 900007c480)