Open mmuurr opened 8 months ago
@mmuurr I agree this looks like a {testthat} bug. For some reason that class of error is not caught. FWIW I might simplify/tighten your workaround as follows:
expect_s3_class(tryCatch(f(), stackOverflowError=identity), "error")
IIRC. this is trickier than it looks because if you've run out of stack space, it's possible that no other code will work. So I'm a bit sceptical we can make this work generally, but @lionel- might know more.
We generally rely on calling error handlers, i.e. ones that run without unwinding the call stack first. These calling handlers are purposefully not run in the case of a R-level stack overflow error to prevent R from crashing from an actual C-level stack overflow.
We could do something like rlang::try_fetch()
which wraps the withCallingHandlers()
call in tryCatch(stackOverflowError = )
to catch these.
Or much easier than changing all our condition handling machinery, provide a dedicated expect_no_stack_overflow()
for this specific case.
As part of developing a package there's a specific pattern I want to detect that leads to an infinite recursion error. (If this error ever doesn't happen, then it's likely I broke something in the logic, hence my desire to test for it.)
This test fails:
This passes, but is a bit clunky:
Should that first
expect_error()
test fail, given that the second passes?({testthat} v3.2.1)