Stream: beginners

Topic: Could main! allow any error to be returned?


view this post on Zulip Aurélien Geron (Jul 29 2026 at 22:28):

In the old Roc compiler, I liked the fact that the main! function could return any error, and it would just be printed out. Now every error has to be mapped to Exit(U32). This is arguably a good thing for production software, but for dev and quick scripts, I find it a bit cumbersome. Perhaps there could be an option to enable the old behavior, for example: roc --dev foo.roc?

view this post on Zulip Bryce Miller (Jul 29 2026 at 22:37):

Hmm, I thought this was up to the platform author. It looks like basic-CLI is still wired up to do this but I haven’t tested it recently so I could be wrong.

view this post on Zulip Aurélien Geron (Jul 29 2026 at 22:39):

Oh thanks, I didn't know it was up to the platform author, that makes sense. So I guess that's a question for @Luke Boswell ?

view this post on Zulip Bryce Miller (Jul 29 2026 at 22:39):

I'm actually about to do some other stuff with basic-cli so I could test it while I'm at it

view this post on Zulip Aurélien Geron (Jul 29 2026 at 22:43):

Btw, the basic CLI platform used to provide Utc.now!, Utc.to_nanos_since_epoch, and Sleep.millis!. It would be great to add these back if possible.

view this post on Zulip Aurélien Geron (Jul 29 2026 at 22:44):

And maybe Http.send! as well?

view this post on Zulip Bryce Miller (Jul 29 2026 at 22:54):

I'm testing with v0.21.0 released 2 days ago, and it appears that it allows arbitrary errors like you want. If you return an error other than Exit(I32) it prints a message and then just does Str.inspect on whatever error you returned.

view this post on Zulip Aurélien Geron (Jul 29 2026 at 22:55):

Oh great, I didn't know 0.21.0 was released, I'll try it out now.

view this post on Zulip Bryce Miller (Jul 29 2026 at 22:55):

Yeah I just noticed the new release myself :sweat_smile:
Looks like it also has Utc.now!

view this post on Zulip Bryce Miller (Jul 29 2026 at 22:56):

At a minimum the Tcp api changed a bit, not sure what else.

view this post on Zulip Aurélien Geron (Jul 29 2026 at 22:57):

Wowowowow

view this post on Zulip Luke Boswell (Jul 29 2026 at 22:57):

Yeah I thought it had sleep and those other functions. Ive got work things on today and cant really look at it closely.

view this post on Zulip Richard Feldman (Jul 29 2026 at 23:05):

Aurélien Geron said:

In the old Roc compiler, I liked the fact that the main! function could return any error, and it would just be printed out. Now every error has to be mapped to Exit(U32). This is arguably a good thing for production software, but for dev and quick scripts, I find it a bit cumbersome. Perhaps there could be an option to enable the old behavior, for example: roc --dev foo.roc?

I'd like to go back to that old design. So the return type of main! becomes Try({}, Exit(I32), ..) and then the platform does a match on that Try with other => crash "The CLI crashed with:\n\n${other.inspect()}"

The nice thing about it is if you want the current API, it's trivial to get - just have main! call a function with that narrower signature and you're all set.

view this post on Zulip Bryce Miller (Jul 29 2026 at 23:13):

It looks like that is the way basic-cli is working currently, except that instead of crashing with a message it's logging to stderr and exiting with 1

view this post on Zulip Richard Feldman (Jul 30 2026 at 00:19):

that also works!


Last updated: Aug 12 2026 at 12:35 UTC