format.expectation() assumes that the "trace" entry of a condition comes from a testthat modified condition (and thus assumes whatever that would imply).
This means that test_that() can expose an internal error rather than a useful trace_back.
library(testthat)
test_that("Testing trace clash", {
cnd <- errorCondition("My error message", trace="hhmmm", class = "foo")
expect_true(stop(cnd))
})
#> ── Error: Testing trace clash ──────────────────────────────────────────────────
#> Error in `if (is.null(x[["trace"]]) || trace_length(x[["trace"]]) == 0L) { return(x$message) }`: missing value where TRUE/FALSE needed
#> Error:
#> ! Test failed.
FWIW - This came up after looking at #2241 and the subsequent discussion in r-lib/rlang#1841. Whilst a different issue, both point to testthat taking a risky (albeit a relatively low-risk) approach of modifying conditions directly rather than wrapping them. I'm not sure about the internals of testthat to know whether this is something easy to change or more involved.