You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We want to improve the ergonomics of error handling in Roc. Below are listed the new tools we want to introduced, followed by example usages, and then a list of child issues each containing more details on implementing the new features.
The primary tool here is the new try keyword, which acts like Result.try, but is not quite the same as how ? currently desugars. It will pair well with the upcoming ! suffix behavior. It is used as a prefix in standard expressions, as well as in pipelines.
We want to pair it with a new ? operator, which acts like Result.mapErr. It can be used to purely or effectfully map over errors, meaning it can't just be syntax sugar. It is lower precedence than try and is used on the same line as an expression, like so:
We also want to add ?? to mean Result.withDefault, which will work almost exactly like ? except that it can go on the next line in a pipelining expression chain.
Since ?? now means Result.withDefault, we should additionally update our default record syntax for types and values to use the same operator. That would look like:
Button a : {
elements : List (Html a),
onClick ?? Handler a,
}
renderButton = { elements, onClick ?? noOpHandler } -> ...
In all, we need the following features implemented:
Design doc: version 1 and version 2
We want to improve the ergonomics of error handling in Roc. Below are listed the new tools we want to introduced, followed by example usages, and then a list of child issues each containing more details on implementing the new features.
The primary tool here is the new
try
keyword, which acts likeResult.try
, but is not quite the same as how ? currently desugars. It will pair well with the upcoming ! suffix behavior. It is used as a prefix in standard expressions, as well as in pipelines.We want to pair it with a new ? operator, which acts like
Result.mapErr
. It can be used to purely or effectfully map over errors, meaning it can't just be syntax sugar. It is lower precedence thantry
and is used on the same line as an expression, like so:We also want to add ?? to mean
Result.withDefault
, which will work almost exactly like ? except that it can go on the next line in a pipelining expression chain.Since ?? now means
Result.withDefault
, we should additionally update our default record syntax for types and values to use the same operator. That would look like:In all, we need the following features implemented:
try
Keyword for Error Propagation #7087The text was updated successfully, but these errors were encountered: