Stream: ideas

Topic: basic-cli: Stdin.lineChecked and friends


view this post on Zulip Kevin Gillette (Dec 09 2022 at 09:14):

(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 a None value', src/lib.rs:310:45
note: run with RUST_BACKTRACE=1 environment 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.

view this post on Zulip Richard Feldman (Dec 09 2022 at 12:26):

seems like a reasonable API! :+1:

view this post on Zulip Richard Feldman (Dec 09 2022 at 12:26):

want to open an issue on basic-cli for it?

view this post on Zulip Brendan Hansknecht (Dec 09 2022 at 15:55):

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.

view this post on Zulip Brendan Hansknecht (Dec 09 2022 at 16:03):

Same with Stdout.line and broken pipes technically.


Last updated: Jun 16 2026 at 16:19 UTC