I think we should consider allowing ?/try even at the top level, but that's out of scope
:thinking: what would that do at the top level?
2 messages were moved here from #contributing > Pull Request for Review by Luke Boswell.
So when I say "at the top level", I mean in the context of top-level expects. I've been thinking of this for a bit, and it seems that even though users can write a try : \{} -> Result XYZ err and call it, that's not as ergonomic as just writing an expect like it is a function.
As such, I'd propose that top-level expects (not inline ones) that have try in them would propagate their errors as is done in Rust 2018, where any Inspectable error is displayed on early return. We'd either require wrapping the bool check at the bottom in Ok or allow bare, there are trade-offs there. Something like:
expect
parsed = try parseDate "invalidDate"
parsed == { year: 2021, month: 5, day: 20 }
Which when run would fail something like this:
> roc test example.roc
...
expect on line 123 failed with error InvalidDateStr
0 tests passed and 1 test failed in 123ms
You could argue that this incentivizes users to "fire and forget" tests and not think about how they should fail, but there are a lot of tests where that's probably not important
oh that's really interesting!
I've been thinking about how I like unwrap in Rust tests but would prefer if it were banned everywhere else, and that's an interesting way to achieve that
If we can make the type system okay with not requiring a wrapping Ok, that'd be nicer to use
The great thing here is that Rust has already showed that this pattern works
one idea would be to say that try inside a top-level expect just fails the test immediately instead of doing what it usually does
then there's no type issue
That works!
try just works subtly differently in expect, I think that's better
We did want to eventually make it such that the actual == expected statement debug prints the actual and expected values without needing to put them in defs first
This would make that easier to do
This sounds like an excellent idea
Sam Mohr said:
We did want to eventually make it such that the
actual == expectedstatement debug prints theactualandexpectedvalues without needing to put them in defs first
yeah I want to generalize this to "whatever the last expression is gets taken apart completely and we print all the sub-expressions"
which includes if the last expression is a pipeline - then, we print all the intermediate steps in the pipeline
Last updated: Jun 16 2026 at 16:19 UTC