Skip to content

Conversation

@lona-k
Copy link
Collaborator

@lona-k lona-k commented Sep 16, 2025

error_*(msg, ...) and warning_*(msg, ...) functions currently cannot handle messages where angle brackets are used, i.e. <*>. This is due to a bug in cli (see r-lib/cli#789) that will hopefully be fixed in the future.


Note

Migrate the codebase to a new structured error/warning system, updating messages, docs, and tests accordingly.

  • Core/API:
    • Replace stopf/warningf with structured condition helpers (error_input, error_config, error_mlr3, error_learner_*, warning_config, warning_input, warning_mlr3) across learners, tasks, measures, resampling, predictions, data backends, and utils.
    • Standardize error/warning messages (incl. minor length checks and wording tweaks) and ensure consistent handling during encapsulation.
  • Helpers:
    • Add format_angle_brackets() to safely format objects in messages (workaround for cli angle-bracket bug).
  • Docs:
    • Document new error and warning classes; minor Rd cleanup.
  • Tests:
    • Update expectations to new messages/classes and wording; adjust a few debug texts and line breaks.

Written by Cursor Bugbot for commit 2835ef2. This will update automatically on new commits. Configure here.

@lona-k lona-k linked an issue Sep 16, 2025 that may be closed by this pull request
Copy link
Member

@be-marc be-marc left a comment

Choose a reason for hiding this comment

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

Changes

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

This PR is being reviewed by Cursor Bugbot

Details

You are on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

# Replace this with x$format() when the issue is solved.
format_angle_brackets = function(x) {
sprintf("<<%s:%s>>", class(x)[1L], x$id)
}
Copy link

Choose a reason for hiding this comment

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

Bug: Double angle brackets in error messages

The format_angle_brackets function produces double angle brackets <<ClassName:id>> instead of single angle brackets <ClassName:id>. This breaks existing test expectations and changes user-facing error message formats. The test at line 252 expects <LearnerRegrRpart:regr.rpart> but will receive <<LearnerRegrRpart:regr.rpart>>. While the function is intended as a workaround for a cli issue with angle brackets, it inadvertently changes the output format in a breaking way.

Additional Locations (2)

Fix in Cursor Fix in Web

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Bug: Incomplete refactoring: stopf not converted to error function

The refactoring to replace stopf with the new condition system functions is incomplete. Three instances of stopf remain unchanged while surrounding code was converted to use error_input and other new error functions. This creates inconsistency in error handling across the codebase and means these errors won't benefit from the new condition system that handles angle brackets correctly.

R/Measure.R#L341-L342

mlr3/R/Measure.R

Lines 341 to 342 in 7b5c2b6

if (!is_scalar_na(self$task_type) && self$task_type != prediction$task_type) {
stopf("Measure '%s' incompatible with task type '%s'", self$id, prediction$task_type)

R/PredictionDataClassif.R#L112-L113

if (length(unique(map_lgl(dots, function(x) is.null(x$extra)))) > 1L) {
stopf("Cannot rbind predictions: Some predictions have extra data, others do not")

R/PredictionDataRegr.R#L109-L110

mlr3/R/PredictionDataRegr.R

Lines 109 to 110 in 7b5c2b6

if (length(unique(map_lgl(dots, function(x) is.null(x$extra)))) > 1L) {
stopf("Cannot rbind predictions: Some predictions have extra data, others do not")

Fix in Cursor Fix in Web


Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Bug: Inconsistent error function usage in Measure class

The PR aims to replace all stopf() calls with the new error system, but several instances were missed. In Measure$obs_loss() at line 342, stopf() is still used for the same error message that was converted to error_input() in Measure$score() at line 267. Similarly, in PredictionDataClassif.R and PredictionDataRegr.R, the error about extra data still uses stopf() while the surrounding errors about weights and predict types were converted to error_input(). These inconsistencies suggest incomplete migration to the new condition system.

R/Measure.R#L341-L342

mlr3/R/Measure.R

Lines 341 to 342 in a073ba9

if (!is_scalar_na(self$task_type) && self$task_type != prediction$task_type) {
stopf("Measure '%s' incompatible with task type '%s'", self$id, prediction$task_type)

R/PredictionDataClassif.R#L112-L113

if (length(unique(map_lgl(dots, function(x) is.null(x$extra)))) > 1L) {
stopf("Cannot rbind predictions: Some predictions have extra data, others do not")

R/PredictionDataRegr.R#L109-L110

mlr3/R/PredictionDataRegr.R

Lines 109 to 110 in a073ba9

if (length(unique(map_lgl(dots, function(x) is.null(x$extra)))) > 1L) {
stopf("Cannot rbind predictions: Some predictions have extra data, others do not")

Fix in Cursor Fix in Web



if (roll("message_train")) {
message("Message from classif.debug->train()")
message("Message from regr.debug->train()")
Copy link

Choose a reason for hiding this comment

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

Bug: Incorrect learner name in debug message

The training message for regr.debug incorrectly references classif.debug instead of regr.debug. The message says "Message from classif.debug->train()" but this is the regression debug learner, so it should say "Message from regr.debug->train()". The predict message at line 134 correctly uses "regr.debug", showing this is an inconsistency.

Fix in Cursor Fix in Web

R/LearnerRegr.R Outdated

if ("quantiles" %nin% self$predict_types) {
stopf("Learner does not support predicting quantiles")
error_learner_predict("Learner does not support predicting quantiles")
Copy link

Choose a reason for hiding this comment

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

Bug: Wrong error type for quantile configuration

The errors when setting quantiles and quantile_response fields use error_learner_predict but should use error_config. These errors occur during configuration when a user tries to set quantile-related fields on a learner that doesn't support quantile prediction, not during actual prediction. Using error_learner_predict incorrectly categorizes this as a prediction failure rather than a configuration error.

Additional Locations (1)

Fix in Cursor Fix in Web

@be-marc be-marc merged commit bf8305b into main Nov 25, 2025
7 checks passed
@be-marc be-marc deleted the errors branch November 25, 2025 13:11
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.

Use new condition system for errors and warnings

3 participants