Skip to content

Better error forwarding in expect_snapshot() #2277

@hadley

Description

@hadley
f <- function() g()
g <- function() h()
h <- function() stop("!")

library(testthat)
test_that("", {
  local_edition(3)
  expect_snapshot(f())
})
#> ── Error:  ─────────────────────────────────────────────────────────────────────
#> Error in `h()`: !
#> Backtrace:
#>     ▆
#>  1. └─testthat::expect_snapshot(f())
#>  2.   └─testthat:::expect_snapshot_(...)
#>  3.     ├─base::withRestarts(cnd_signal(state$error), muffle_expectation = function() NULL)
#>  4.     │ └─base (local) withOneRestart(expr, restarts[[1L]])
#>  5.     │   └─base (local) doWithOneRestart(return(expr), restart)
#>  6.     └─rlang::cnd_signal(state$error)
#> Error:
#> ! Test failed with 1 failure and 0 successes.

Created on 2025-11-03 with reprex v2.1.1

How can we get the original traceback here?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions