Skip to content

expect_error() (& friends) error could be friendlier for mis-named argument #2054

Open
@MichaelChirico

Description

@MichaelChirico

Updating to 3.2.3 broke some tests. The biggest thing was usage like this:

Sys.setenv(TESTTHAT_EDITION=3)
expect_error(stop("hello"), msg="bye")

### 3.2.1.1
# Warning message:
# In expect_error(stop("hello"), msg = "bye") :
#   Arguments in `...` must be used.
# ✖ Problematic argument:
# • msg = "hello"
# ℹ Did you misspell an argument name?

### 3.2.3
# Error in `expect_error()`:
# ! Can't specify `...` without `pattern`.
# Run `rlang::last_trace()` to see where the error occurred.

Previously, the tests would pass somewhat spuriously, as in effect the msg argument is totally ignored, i.e. it's equivalent to just running expect_error(stop("hello")) which only checks the condition is thrown, not its contents.

The change in 3.2.3 is definitely for the better (this flushed out some tests checking for the wrong message), but the old warning was clearer & more actionable. Even putting aside #2053, it's hard to tie together "... is specified" means "some named argument didn't match formals --> wound up passing to ...". Simply restoring the informative "problematic argument" tag would do a lot.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions