Skip to content
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

conversion of warnings and errors to cli #954

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Conversation

topepo
Copy link
Member

@topepo topepo commented Oct 23, 2024

pal was a godsend here 💯

@@ -372,37 +364,37 @@ check_metrics <- function(x, object) {
is_surv_metric_set <- inherits(x, c("survival_metric_set"))

if (!is_numeric_metric_set && !is_class_prob_metric_set && !is_surv_metric_set) {
rlang::abort("The `metrics` argument should be the results of [yardstick::metric_set()].")
cli::cli_abort("The {.arg metrics} argument should be the results of
{.fn yardstick::metric_set}.")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previous messages has [pkg:fun()] format. Do we want to move to that? I don't think that they were clickable.

"The first argument needs to be an object with class 'tune_results'."
)
cli::cli_abort("The first argument needs to be {.cls tune_results} object,
not {.obj_type_friendly {mtcars}}.")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm using obj_type_friendly a lot in these messages.

cli::cli_abort(
"There is no `fit_best()` method for an object with \\
{cli::qty(cls)} class{?es} {.var {cls}}."
"No {.fn fit_best} exists for {.obj_type_friendly {x}}."
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I standardized on this message for all of the main default methods.

@@ -117,16 +116,17 @@ last_fit.model_fit <- function(object, ...) {
))
}

tune_pp_msg <- "To tune a model specification, you must preprocess with a
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More standardization

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicely done!

@@ -322,7 +320,8 @@ plot_param_vs_iter <- function(x, call = rlang::caller_env()) {
param_cols <- get_param_columns(x)
pset <- get_param_object(x)
if (is.null(pset)) {
rlang::abort("`autoplot()` requires objects made with tune version 0.1.0 or later.")
cli::cli_abort("{.fn autoplot} requires objects made with {.pkg tune}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe time to retire this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.

@@ -107,11 +107,10 @@ reduce_all_outcome_names <- function(resamples) {
}

if (n_unique > 1L) {
rlang::warn(paste0(
"More than one set of outcomes were used when tuning. ",
"This should never happen. ",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was weirdly aggro. Ahh, me in July 2021. I blame the 'rona.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hahahaha i feel like this is the most likely error i see when i introduce bugs in the grid code paths

@simonpcouch simonpcouch marked this pull request as ready for review October 29, 2024 20:58
Copy link
Contributor

@simonpcouch simonpcouch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this PR is going to make tidymodels feel much more modern/slick for many users. Heck yeah!

}
lab <- "the confidence bound"
if (rlang::is_function(kappa)) {
farg <- names(formals(kappa))
if (length(farg) == 0) {
rlang::abort("The `trade_off` function should have at least one argument.")
cli::cli_abort("The {.fn trade_off} function should have at least one argument.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cli::cli_abort("The {.fn trade_off} function should have at least one argument.")
cli::cli_abort("The {.fn kappa} function should have at least one argument.")

I think this error should have referenced this argument all along?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seeing that it's maybe ambiguous whether to use .fn or .arg in these—fine with me to go the route you've chosen.

Comment on lines +29 to +31
cli::format_inline("Unknown case weights object contains
{.obj_type_friendly {x}} instead of an object with a
case weight class."),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cli::format_inline("Unknown case weights object contains
{.obj_type_friendly {x}} instead of an object with a
case weight class."),
"Unknown case weights object contains {.obj_type_friendly {x}} instead
of an object with a case weight class.",

paste0("Unknown case weights object with class <", class(x)[[1]], ">. "),
cli::format_inline("Unknown case weights object contains
{.obj_type_friendly {x}} instead of an object with a
case weight class."),
i = paste0(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This paste0() can be removed and made a string with a(n implicit) newline

i = paste0(
"Define a `.use_case_weights_with_yardstick()` method for this type to ",
"Define a {.fn .use_case_weights_with_yardstick} method for this type to ",
"declare whether or not these case weights should be passed on to yardstick."
),
i = "See `?.use_case_weights_with_yardstick` for more information."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
i = "See `?.use_case_weights_with_yardstick` for more information."
i = "See {.help .use_case_weights_with_yardstick} for more information."

"The `.predictions` column does not exist. ",
"Refit with the control argument `save_pred = TRUE` to save predictions."
cli::cli_abort(
"The {.code .predictions} column does not exist. Please refit with the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"The {.code .predictions} column does not exist. Please refit with the
"The {.field .predictions} column does not exist. Please refit with the

following Emil's lead here

}

out <- attr(x, "outcomes", exact = TRUE)

if (is.null(out)) {
rlang::abort("'tune_results' object doesn't have an 'outcomes' attribute.")
cli::cli_abort("The object of type {.cls tune_results} object doesn't have an
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cli::cli_abort("The object of type {.cls tune_results} object doesn't have an
cli::cli_abort("The object of type {.cls tune_results} doesn't have an

cli::cli_warn(
"The {.code ...} are not used in this function but {length(dots)}
object{?s} {?was/were} passed: {.val {names(dots)}}"
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ref #829

! There are 5 tuning parameters and 1 grid point was requested.
* The GP model requires 2+ initial points. For best performance, supply more initial points than there are tuning parameters.
i The GP model requires 2+ initial points. For best performance, supply more initial points than there are tuning parameters.
i
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty i = "", it seems

@@ -4,7 +4,7 @@
.use_case_weights_with_yardstick(1)
Condition
Error in `.use_case_weights_with_yardstick()`:
! Unknown case weights object with class <numeric>.
! Unknown case weights object contains a number instead of an object with a case weight class.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if this can be more succinct / plainly written

Comment on lines +168 to +171
num_unk <- length(unk_names)
msg <- cli::format_inline(
"Creating pre-processing data to finalize {num_unk} unknown parameter{?s}: {.val {unk_names}}"
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
num_unk <- length(unk_names)
msg <- cli::format_inline(
"Creating pre-processing data to finalize {num_unk} unknown parameter{?s}: {.val {unk_names}}"
)
msg <-
"Creating pre-processing data to finalize unknown parameter{?s} {.val {unk_names}}."

Since this is a very common message I am going to be fussy about my enum-after-parens pet peeve--feel free to ignore that part of this suggestion if you please🤪

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants