Issue #1360: println, print, eprintln and eprint throw io::IoError and never panic; nikaia migrate print-throws (ADR-392)

Open and answer this issue on GitHub.

ready · opened 2026-11-07 · updated 2026-11-07 · 0 comments

Decision in force (owner, 2026-11-07): ADR-392

A failed write to stdout/stderr throws io::IoError; none of the four print functions panics (today they lower to Rust’s println!, which panics on a closed pipe). A function that prints says throws or catches, main included (Part I 7.1). nikaia migrate print-throws moves the programs. Part III 17.1 says so (27284b4).

Scale: about 3100 calls in about 1050 .nika files, plus about 260 in Markdown (guide, website, docs).

Probe

fn main() {
    println("hello")
}

After the build: refused with NK2605 (println can fail with io::IoError), help “Add throws to main, or handle it at the call”. fn main() throws { println("hello") } builds; nikaia run main.nika | head -0 ends with status 1 and the message io::IoError: broken pipe (or the OS text) on stderr, not a Rust panic.

To build

  1. std: the four functions write through a fallible writer and return the error (crates/nikaia-std/src/io.rs; the lowering of println(f"…") in the emitter); std.contracts entries throws = ["io::IoError"], panics = false. A failed write to stderr inside the error report of main is not retried.
  2. Checker: nothing new: the throw-set inference picks it up from the entries. Check that NK2605’s help reads well for a print.
  3. nikaia migrate print-throws PATH... as a tools/*.nika behind the migrate subcommand, like migrate views-3: adds throws to every function whose only new failure is a print, and to its callers as far as the failure reaches; a function that already has throws or catches everything is left alone; works on .nika and the Nikaia blocks of Markdown.
  4. Move the repository with it in one commit: tests/, examples/, packages/, benches/, tools/*.nika, scripts/*.nika, crates/nikaia-std/src/tools/*.nika (and re-lower), guide/, website/, README.md, the specification’s examples. Rust it tests that hold Nikaia sources: changed only to keep them passing.
  5. Tests in tests/compiler/: the probe refused; with throws it runs; a closed-pipe test (a program printing in a loop, its stdout closed) ends with status 1 and the message, not a panic; a catch around a println runs its handler.

Done when

No print function panics on a failed write, every program in the repository builds under the rule, and the suite is green.

Needed by #1355 (with D35, a task that prints then has an ordinary io::IoError, not a possible crash).

Back to Open Issues