ropensci/targets

Clickable links in the main error message (both URLs and code)

Closed this issue · 4 comments

@hadley suggested this in #1310 (reply in thread). I did improve the main error message of tar_make() recently, but I am not sure how to make the text clickable.

I found cli::style_hyperlink() from looking at the rlang source code. That should work.

Actually, cli_text() is what we should be using:

> cli::cli_text("Help on run {.run rlang::abort('oh no')}")
Help on run rlang::abort('oh no')
> rlang::abort('oh no')
Error:
! oh no
Run `rlang::last_trace()` to see where the error occurred.
> cli::cli_text("Help on run {.url https://github.com}")
Help on run <https://github.com>

Switching back to style_hyperlink because cli_text() is having trouble getting code links to work. This is the best I have found:

cli_code <- function(code) {
  cli::style_hyperlink(text = code, url = paste0("x-r-run:", code))
}

cli_code("targets::tar_meta(x)") works, but the links are not clickable for any of cli_code("targets::tar_meta(any_of(x))"), cli_code("tar_meta(x)"), or cli_code("targets::tar_meta(x)$error"). So trying to added would be inconsistent and set up user expectations to be frustrated. Let's stick with the URLs until there is better support for clickable code.

Added clickable URLs in bc8afb5.