(forked from https://roc.zulipchat.com/#narrow/stream/231634-beginners/topic/Task.2Ferror.20handling.20.26.20platform.20use/near/314385634)
Given the following program:
main = await Stdin.line Stdout.line
When running it, if Ctrl-D is used (on a Unix-like system at least), the following panic occurs:
thread 'main' panicked at 'called
Option::unwrap()on aNonevalue', src/lib.rs:310:45
note: run withRUST_BACKTRACE=1environment variable to display a backtrace
fatal runtime error: failed to initiate panic, error 5
In general, the inability to detect EOF is particularly limiting for a Stdin implementation. Perhaps a variant function Stdlin.lineChecked could be exposed to cover this case, leaving Stdin.line for cases where the caller assumes input will be available?
fwiw, detecting file-closed or broken-pipe conditions is also important for writing efficient, graceful stream processors. Imagine a Roc program producing millions of lines of output is being passed to the head utility: ideally, the Roc program should be able to detect the inability to write and save work by exiting early.
seems like a reasonable API! :+1:
want to open an issue on basic-cli for it?
I think this should just be functionality of Stdin.line directly. The main reason it isn't is because the platform isn't mature and does not handle a lot of errors. Claiming Stdin.line can't fail to the end user is just hiding errors, and i think we should avoid that.
Same with Stdout.line and broken pipes technically.
Last updated: Jun 16 2026 at 16:19 UTC