-
Notifications
You must be signed in to change notification settings - Fork 70
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_warning
and cli_inform
don't expose individual bullet points in condition object.
#666
Comments
If you need extra information in the error object, then you can add that directly, and possibly create a new error class. It does not seem like a good idea to try to infer information from the message. E.g. error and warning messages might be translated in the future. |
I understand that trying to save useful data into the error's fields is a bit of a code smell and not a good idea. In this case however I'm only trying to write some Regardless, it is also surprising (to me at least) that |
I suppose it would make sense to make them behave the same way, but it is not entirely clear at this point whether that'll break existing code. In any case, whatever is in
I think you can use that to match your error message, with a constant or Personally, I would use |
I am going to close this, as it seems that there is nothing actionable. |
The
cli_warning
andcli_inform
functions work by formatting their arguments as a single string, which then gets passed on torlang::warn
/rlang::inform
Unfortunately this means that when inspecting the produced condition objects programmatically (using
testthat::expect_warning
for example), the bullet points cannot be accessed individually, which makes it harder to write assertions against.This behaviour is inconsistent with
cli_abort
, which instead formats each bullet point separately and passes a vector torlang::error
. By doing this, the main message is available in the condition object as$message
, and the rest of the bullet points are available as$body
.See below the difference between
cli_abort
, whose additional bullets are available ase$body
, and warnings.If the implementation of
cli_warning
error was closer tocli_abort
then the bullet points would be available in the warning object.To be honest this seems like an easy fix by copying the implementation of
cli_abort
, and I'd be happy to make a PR for it. However I feel there might be a reason for the inconsistent behaviour that I am missing.The text was updated successfully, but these errors were encountered: