{"record":{"id":"65aee3b5600a3c7c","repo":"atuinsh/atuin","slug":"failed-printing-to-stdout-e","errorCode":null,"errorMessage":"failed printing to stdout: {e}","messagePattern":"failed printing to stdout: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/atuin/src/command/client/init/bash.rs","lineNumber":53,"sourceCode":"    write_tmux_config(writer, options.tmux)?;\n    writeln!(writer, \"__atuin_bind_ctrl_r={bind_ctrl_r}\")?;\n    writeln!(writer, \"__atuin_bind_up_arrow={bind_up_arrow}\")?;\n    writeln!(writer, \"{}\", BASH.main)?;\n\n    #[cfg(feature = \"ai\")]\n    if options.enable_ai {\n        writeln!(writer, \"{}\", atuin_ai::shell::BASH_INIT)?;\n    }\n\n    writeln!(writer, \"}}\") // end include guard\n}\n\npub fn init_static(options: &StaticInitOptions<'_>) {\n    if let Err(e) = write_static_init(&mut io::stdout().lock(), options) {\n        // This function used to use `println!`, which panics on write failure with this same\n        // message. Using a locked `Stdout` object is faster, but `write!` returns an error rather\n        // than panicking, so we manually panic here to keep the same behavior.\n        panic!(\"failed printing to stdout: {e}\");\n    }\n}\n","sourceCodeStart":35,"sourceCodeEnd":56,"githubUrl":"https://github.com/atuinsh/atuin/blob/900007c48045867e7f44b0f9bc55ad9dbe99ee0d/crates/atuin/src/command/client/init/bash.rs#L35-L56","documentation":"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.","triggerScenarios":"`atuin init <shell>` (via init_static) when the underlying write to stdout fails — closed stdout, broken pipe, or full disk.","commonSituations":"Piping `atuin init bash` into `head` or a closed consumer, redirecting stdout to a full filesystem, or a terminal that has gone away.","solutions":["Ensure stdout is open and its consumer is still reading","Avoid piping init output into commands that exit early (e.g. `| head`) — use `eval \"$(atuin init bash)\"` instead","Check disk space if stdout is redirected to a file","Capture the io::Error `{e}` in the panic for the real cause"],"exampleFix":"// before\natuin init bash | head -20\n// after\neval \"$(atuin init bash)\"","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match std::panic::catch_unwind(|| atuin::command::client::init::bash::init_static(&opts)) {\n    Ok(_) => {},\n    Err(_) => eprintln!(\"atuin init failed: stdout not writable\"),\n}\n// or avoid the failure: consume stdout fully instead of piping to early-exiting commands","preventionTips":["Don't pipe `atuin init` into commands that close the pipe early","Use `eval \"$(atuin init bash)\"` in shell rc files","Keep stdout targets (files/disks) healthy"],"tags":["io","stdout","panic","broken-pipe"],"backgroundTag":"broken-pipe","analyzedSha":"900007c48045867e7f44b0f9bc55ad9dbe99ee0d","analyzedAt":"2026-09-19T12:52:51.491Z","contentChangedAt":"2026-09-19T12:52:51.491Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}