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

error_arg() and error_call() should have better fall backs when called directly #1667

Open
hadley opened this issue Nov 9, 2023 · 3 comments

Comments

@hadley
Copy link
Member

hadley commented Nov 9, 2023

library(rlang)

foo <- function(x, arg = caller_arg(x), call = caller_env()) {
  cli::cli_abort("Error {.arg {x}}", call = call)
}
foo(123)
#> Error:
#> ! Error `123`

Created on 2023-11-09 with reprex v2.0.2.9000

Ideally this would be

#> Error: foo()
#> ! Error `x`
@lionel-
Copy link
Member

lionel- commented Nov 13, 2023

Unfortunately I don't think we can do better here.

@lionel-
Copy link
Member

lionel- commented Nov 13, 2023

Though we could detect calls at top-level. The behaviour would then differ when called directly vs in a browser or in testthat or markdown.

@hadley
Copy link
Member Author

hadley commented Nov 13, 2023

The thing that makes me think we could do better is that it's the same appearance at the top level and in snapshot:

Code
  foo(123)
Condition
  Error:
  ! Error `123`

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