-
Notifications
You must be signed in to change notification settings - Fork 71
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
cli_inform doesn't invoke cli.default_handler #712
Comments
Yes, that's a mistake in the documentation, those functions indeed do not use the regular cli code path. |
Thanks for the clarification. Wondering if something like this might be a palatable alternative: alt_inform <- function(message, ..., .envir = parent.frame()) {
outer_cnd <- catch_cnd(
rlang::inform(cli::format_message(message, .envir = .envir), ...)
)
cnd <- catch_cnd(
cli::cli_verbatim(
format(outer_cnd)
)
)
handler <- getOption("cli.default_handler", cli:::cli_server_default)
handler(cnd)
cnd_signal(outer_cnd)
invisible(NULL)
} |
|
My hope was to use the default handler functionality to intercept cli_* calls and reroute them into a log. In general, I wouldn't have access to the source code that invokes the cli_* calls. Seems like it wasn't designed for this use case. No worries. Thanks for the comments. |
You can always catch all messages, if that helps with your use case: ❯ msgs <- list(); withCallingHandlers(cli::cli_inform("good to know"), message = function(m) msgs <<- c(msgs, list(m)))
good to know
❯ msgs
[[1]]
<message/rlang_message>
Message:
good to know |
Based on https://cli.r-lib.org/articles/semantic-cli.html#cli-messages, I would expect
cli_abort
,cli_warn
, andcli_inform
to call the handler specified incli.default_handler
. However, these particular functions wrap theirrlang
analogues and seemingly wind up on another code path.Here's a simple reproducible example. The first
expect_output
behaves as expected; the second, fails.Hoping this has an easy workaround; and apologies if I overlooked something in the documentation. Thanks for all your work on the
cli
project!The text was updated successfully, but these errors were encountered: