Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Error Handling Ergonomics #7086

Open
1 of 4 tasks
Tracked by #7106
smores56 opened this issue Sep 18, 2024 · 0 comments
Open
1 of 4 tasks
Tracked by #7106

Improve Error Handling Ergonomics #7086

smores56 opened this issue Sep 18, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@smores56
Copy link
Collaborator

smores56 commented Sep 18, 2024

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 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:

fileContent = try File.read! "file.txt" ? FileReadErr

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.

confileFile = args.configPath ?? "~/.config/service.json"

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:

@smores56 smores56 pinned this issue Sep 18, 2024
@lukewilliamboswell lukewilliamboswell added the enhancement New feature or request label Sep 18, 2024
@smores56 smores56 mentioned this issue Sep 19, 2024
4 tasks
@smores56 smores56 unpinned this issue Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants