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

Helper to wrap error with a hint #1692

Open
hadley opened this issue Feb 21, 2024 · 3 comments
Open

Helper to wrap error with a hint #1692

hadley opened this issue Feb 21, 2024 · 3 comments

Comments

@hadley
Copy link
Member

hadley commented Feb 21, 2024

In some situations you know the probable cause of an error, and there's a specific fix that the user might want to try first. Ideally this would be added as some sort of trailing hint, but we don't have a great technique for that currently.

e.g. tidyverse/dbplyr#1459, https://github.com/r-dbi/odbc/pull/744/files#diff-ef8dcd24d5337937983c4c56ba9146ec1fd06d22851849ff570ffdc7ad051a58R33

@lionel-
Copy link
Member

lionel- commented May 31, 2024

Does this help?

wrap <- function(expr) {
  withCallingHandlers(
    expr,
    error = function(cnd) {
      abort(cnd_message(cnd), footer = c("i" = "bar"))
    }
  )
}

wrap(1 + "")
#> Error in `h()`:
#> ! non-numeric argument to binary operator
#> ℹ bar

@hadley
Copy link
Member Author

hadley commented May 31, 2024

Yes!

@lionel-
Copy link
Member

lionel- commented May 31, 2024

oh weird :/

wrap(cli::cli_abort(c("a", i = "b", x = "c")))
#> Error:
#> ! a ℹ b ✖ c
#> ℹ bar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants