assertthat icon indicating copy to clipboard operation
assertthat copied to clipboard

Fix custom error messages for nested functions

Open banfai opened this issue 4 years ago • 0 comments

Fixes #70

It's not a problem with lazy evaluation or promises, it's caused by the incorrect propagation of msg. If one of the assertions is already coming from assert_that then it has an msg attribute, this has to be propagated further.

Test is added to check this: assert_that(assert_that(FALSE, msg = "inner"), msg = "outer") should fail with "inner".

Reprex from #70 after this PR:

inner_f <- function(argument) {
  assertthat::assert_that(argument > 0, msg = "inner_f")
  argument
}

outer_f <- function(argument) {
  assertthat::assert_that(argument > 0, msg = "outer_f")
}

outer_f(inner_f(0))
#> Error: inner_f

Created on 2021-11-04 by the reprex package (v2.0.1)

The added test and all other tests pass correctly.

banfai avatar Nov 04 '21 20:11 banfai