assertthat
assertthat copied to clipboard
Fix custom error messages for nested functions
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.