greta-dev / greta-dev/greta

explore using classed errors in rlang's abort, warn, inform

Open
#375 5 comments 0 reactions 1 assignee Claimed by @njtierney View on GitHub
refactor Up Next
Dominant language
C++
Stars
607
Forks
67
Avg merge
3d 8h
Merged PRs (30d)
1

Description

https://rlang.r-lib.org/reference/abort.html

This allows for classed errors to be passed to the user as well as doing nicer printing of the error messages.

The user then might be able to control what happens with the error, e.g.,

```r

# Give a class to the error:
abort("Something bad happened", "somepkg_bad_error")

# This will allow your users to handle the error selectively
tryCatch(
somepkg_function(),
somepkg_bad_error = function(err) {
warn(conditionMessage(err)) # Demote the error to a warning
NA # Return an alternative value
}
)
```

as it states in the documentation

```
# Unhandled errors are saved automatically by `abort()` and can be
# retrieved with `last_error()`.
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.