atuinsh/atuin · error

failed printing to stdout: {e}

Error message

failed printing to stdout: {e}

What it means

The bash init script is written to stdout; because `write!` returns errors instead of panicking like `println!`, this explicit panic preserves the original panic behavior when stdout cannot be written.

Source

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

    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}");
    }
}

pub async fn init(
    aliases: AliasStore,
    vars: VarStore,
    options: &StaticInitOptions<'_>,
) -> Result<()> {
    init_static(options);

    let aliases = atuin_dotfiles::shell::bash::alias_config(&aliases).await;
    let vars = atuin_dotfiles::shell::bash::var_config(&vars).await;

    println!("{aliases}");
    println!("{vars}");

    Ok(())
}

View on GitHub (pinned to c0c717ab04)

Solutions

  1. Avoid piping atuin init output to commands that close the pipe early
  2. Check that stdout is writable and the disk is not full
  3. Re-run the command with stdout attached to a terminal or a file

Example fix

// before
atuin init bash | head -5
// after
atuin init bash > atuin-init.sh
Defensive patterns

Strategy: try-catch

Validate before calling

// check stdout is writable before invoking
if !std::io::stdout().is_terminal() && std::env::var("ATUIN_INIT_OUT").is_err() {
    eprintln!("stdout may not be writable; redirect output to a file");
}

Try / catch

match Command::new("atuin").args(["init", "bash"]).status() {
    Ok(s) if s.success() => {}
    Err(e) => eprintln!("atuin init failed: {e}"),
    _ => eprintln!("atuin init failed (stdout write error?)"),
}

Prevention

When it happens

Trigger: `atuin init bash` (via `init_static`) when stdout is closed, a broken pipe (e.g. piping to `head` or a exited process), or the fd is otherwise unwritable

Common situations: `atuin init bash | head -1`, redirecting stdout to a full disk or closed fd, running under a shell wrapper that closes stdout

Related errors


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