Skip to content

Conversation

@hadley
Copy link
Member

@hadley hadley commented Nov 10, 2025

This ensures that their backtraces point to the source of the error, not the internals of expect_snapshot()

Fixes #2277

This ensures that their backtraces point to the source of the error, not the internals of `expect_snapshot()`

Fixes #2277
@hadley hadley requested review from Copilot and lionel- November 10, 2025 14:53
@claude
Copy link

claude bot commented Nov 10, 2025

Claude finished @hadley's task —— View job


Reviewing PR: Entrace unexpected errors in snapshots

Todo List:

  • Read repository guidelines (CLAUDE.md)
  • Examine core changes in R/verify-output.R
  • Review test changes and snapshot updates
  • Analyze for potential bugs or issues
  • Provide review feedback

Review Analysis

The core change in R/verify-output.R:89 adds rlang::entrace(cnd) to the error handler in verify_exec(). This ensures error backtraces in snapshots point to the source rather than expect_snapshot() internals.

Key observations:

  1. Correct implementation: The change properly adds calling_handlers = list(error = function(cnd) rlang::entrace(cnd)) to the evaluate::new_output_handler()
  2. Dependencies satisfied: rlang is imported globally via @import rlang in testthat-package.R:89
  3. Test coverage: New test case validates the fix with a clear call chain (f() -> g() -> h())
  4. Snapshot updates: All affected snapshots correctly updated to show improved backtraces

Issues found:

  • Line numbers in test snapshots shifted but updates look correct
  • Error condition type changed from simpleError to rlang_error in snapshots - expected behavior with entracing

LGTM

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances error handling in snapshot testing by ensuring that unexpected errors within expect_snapshot() produce backtraces that point to the source of the error rather than the internals of the snapshot mechanism. This is achieved by adding error entracing via rlang::entrace() in the verify_exec handler.

Key Changes:

  • Added error entracing to the verify_exec() function's output handler to capture meaningful backtraces for errors occurring within snapshots
  • Added a test case to verify that errors in snapshots produce useful backtraces
  • Updated snapshot test outputs to reflect the new error handling behavior

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
R/verify-output.R Added rlang::entrace() as an error handler in the evaluate output handler to capture backtraces
tests/testthat/reporters/backtraces.R Added test case demonstrating error backtrace behavior in snapshots
tests/testthat/test-reporter-progress.R Set TESTTHAT_MAX_FAILS to Inf to ensure all test failures are captured
tests/testthat/_snaps/reporter-progress.md Updated snapshot to include the new test case and adjusted line numbers
tests/testthat/_snaps/snapshot.md Changed error class from simpleError to rlang_error due to entracing
tests/testthat/_snaps/snapshot-reporter.md Updated error message format to include "Error:" prefix
NEWS.md Documented the improvement to snapshot error backtraces

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

* `expect_snapshot()` on reports how to resolve failures once when running inside `R CMD check`.
* `expect_snapshot()` no longer skips on CRAN, as that skips the rest of the test. Instead it just returns, neither succeeding nor failing (#1585).
* `expect_snapshot()` and `expect_snapshot_file()` hints now include the path to the package, if it's not the current working directory (#1577).
* `expect_snapshot()` gives a more informative backtrace when the code inside the snapshot errors (#2277).
Copy link

Copilot AI Nov 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected spelling of 'Entrace' to 'Entrance' in PR title; however, the term should be 'Entraces' (verb form) to match the technical usage in the code.

Copilot uses AI. Check for mistakes.
@hadley hadley mentioned this pull request Nov 10, 2025
24 tasks
Copy link
Member

@lionel- lionel- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG!

@hadley hadley merged commit c32520b into main Nov 11, 2025
15 checks passed
@hadley hadley deleted the entrace-snapshot-errors branch November 11, 2025 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Better error forwarding in expect_snapshot()

3 participants