ADR-392: Writing Output Can Fail, and Says So — println, print, eprintln and eprint Throw io::IoError and Never Panic

Status: Accepted Date: November 7, 2026 (owner’s decision) Answers: #1355 (what a failed write does under ADR-async-v7 D35) Related: Part I 7.1 (a function without throws cannot fail); Part III 17.1 (writing output); ADR-async-v7 D35 (a task’s crash is a failure only where the task can panic)

1. Question

A write to standard output or standard error can fail: the reader closed the pipe (prog | head), the disk behind a redirect is full, the descriptor was closed. Until now the four print functions lowered to Rust’s println!, which panics then. Under D35 that made every function that prints able to panic, so every task that prints would have to handle task::Crashed, a failure that names the wrong thing. Part III 17.1 said nothing about it.

2. Options

3. Decision: B

D1 - The four print functions throw io::IoError when the write fails, and never panic.

println(text), print(text), eprintln(text) and eprint(text) report a failed write as io::IoError, the error every other write in std throws. Their ledger entries say throws = ["io::IoError"] and panics = false.

D2 - The ordinary rule, no exception.

A function that prints can fail, so it says throws or handles the failure with catch (Part I 7.1), main included. An io::IoError that leaves main ends the program with exit status 1 and its message on standard error, as every other error does; a failed write to standard error itself is not written again.

D3 - Moving the programs.

nikaia migrate print-throws PATH... adds throws to every function whose body can now fail only because it prints (and to its callers, as far as the new failure reaches), and leaves a function that already handles failures alone. The repository’s programs, tests, examples, guide and website are moved with it in the commit that builds D1.

4. Consequences

This site is open source. Improve this page.