cli icon indicating copy to clipboard operation
cli copied to clipboard

Use `.internal` argument with `cli::cli_abort()`

Open olivroy opened this issue 2 years ago • 4 comments

I am developing a package. I am switching my error calls from rlang::abort() to cli::cli_abort()

abort("Problem", .internal = TRUE)
This is an internal error in the canadr package, please report it to the package authors.
cli::cli_abort("Problem", .internal = TRUE)
This is an internal error in the cli package, please report it to the
  package authors.

But in the cli documentation, it is written that the ... are passed from cli::abort() to rlang::abort()


I don't know how to provide a reprex.

olivroy avatar Jun 29 '22 00:06 olivroy

@lionel- Is there a workaround here? Setting .frame does not seem to help.

gaborcsardi avatar Jun 29 '22 08:06 gaborcsardi

Do you have latest rlang?

foo <- function() {
  cli::cli_abort("foo", .internal = TRUE)
}
environment(foo) <- rlang::ns_env("purrr")

foo()
#> Error in `foo()`:
#> ! foo
#> ℹ This is an internal error in the purrr package, please report it to the
#>   package authors.

lionel- avatar Jun 29 '22 10:06 lionel-

@lionel- I've also experienced this issue with the latest rlang.

Update: I found I could fix it by setting .frame = current_env(). Perhaps {cli} could set .frame = caller_env() when the user has set .internal = TRUE?

davidchall avatar Jul 08 '22 03:07 davidchall

@davidchall You also need dev cli for a full fix, see #479.

lionel- avatar Jul 08 '22 06:07 lionel-

So as I understand this is fixed now, and there is nothing to do in cli?

gaborcsardi avatar Aug 23 '22 13:08 gaborcsardi