-
Notifications
You must be signed in to change notification settings - Fork 130
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
Improve error messages with cli #560
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #560 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 26 26
Lines 1184 1179 -5
=========================================
- Hits 1184 1179 -5
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Precisions on what I did.
@@ -111,7 +111,7 @@ convert_to_datetime_helper.Date <- function(x, ..., tz = "UTC", out_class = c("P | |||
ret | |||
} | |||
|
|||
convert_to_datetime_helper.character <- function(x, ..., tz = "UTC", character_fun = lubridate::ymd_hms, string_conversion_failure = c("error", "warning"), out_class = c("POSIXct", "Date")) { | |||
convert_to_datetime_helper.character <- function(x, ..., tz = "UTC", character_fun = lubridate::ymd_hms, string_conversion_failure = c("error", "warning"), out_class = c("POSIXct", "Date"), error_call = rlang::caller_env()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to ensure that it print Error in convert_date()
/ convert_datetime()
instead of `Error in convert_to_datetime_helper
c( | ||
"Not all character strings converted to class {.cls {out_class}}.", | ||
i = "{n_not_converted} value{?s} not converted: {.val {not_converted_values}}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using cli pluralization + inline markup https://cli.r-lib.org/index.html#pluralization https://cli.r-lib.org/reference/inline-markup.html. Also cli automatically makes the display of values shorter, hence the removal of the code above that prepares printing of the diagnostic.
expect_warning( | ||
expect_error( | ||
convert_to_date(LETTERS), | ||
regexp = "Not all character strings converted to class Date." | ||
), | ||
regexp = "All formats failed to parse." # lubridate warning | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
duplicated test.
Maybe later! the task is large and may not be worth the trouble currently. |
Description
This is just a little proof of concept of how we can improve messages in janitor, using the power of cli.
It is a little difficult to easily see the diff since we decided against using snapshot tests for errors, but I will add before and after screenshots.
If you think this is a reasonable approach, I will try replicating for other common error messages in janitor.
Related Issue
Addresses #549
Example
with this PR
convert_to_date(LETTERS)
Before: