Skip to content

expect_error() regexpr matching parent errors #1493

@romainfrancois

Description

@romainfrancois

As part of doing the rev dep checks for dplyr 1.0.8 tidyverse/dplyr#6080 there are some packages that start to fail because expect_error() does not match the pattern, because the message is now in a parent condition.

library(testthat)
library(rlang)
#> 
#> Attaching package: 'rlang'
#> The following objects are masked from 'package:testthat':
#> 
#>     is_false, is_null, is_true

f <- function() {
  abort("hello")
}
g <- function() {
  withCallingHandlers(f(), error = function(cnd) {
    abort("bonjour", parent = cnd)
  })
}

expect_error(g(), "Hello")
#> Error: `g()` threw an error with unexpected message.
#> Expected match: "Hello"
#> Actual message: "bonjour"
tryCatch(g(), error= print)
#> <error/rlang_error>
#> Error:
#>   bonjour
#> Caused by error in `f()`:
#>   hello
#> Backtrace:
#>  1. base::tryCatch(g(), error = print)
#>  5. global g()
#>  7. global f()

Created on 2021-11-17 by the reprex package (v2.0.1.9000)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions