Skip to content

Report base error class#2307

Merged
hadley merged 3 commits into
mainfrom
base-error
Jan 7, 2026
Merged

Report base error class#2307
hadley merged 3 commits into
mainfrom
base-error

Conversation

@hadley

@hadley hadley commented Jan 6, 2026

Copy link
Copy Markdown
Member

In #2283 we started entracing snapshots so that we get useful backtraces if snapshot code unexpectedly errors. This had the unfortunate side-effect of changing the reported class for expected errors. We now show the original message if it was an entraced error.

Fixes #2286.

In #2283 we started entracing snapshots so that we get useful backtraces if snapshot code unexpectedly errors. This had the unfortunate side-effect of changing the reported class for expected errors. We now show the original message if it was an entraced error.
@hadley hadley requested a review from lionel- January 6, 2026 23:46
@claude

claude Bot commented Jan 6, 2026

Copy link
Copy Markdown

Claude finished @hadley's task —— View job


Code Review

  • Read repository guidelines
  • Review changed files
  • Analyze implementation
  • Provide feedback

The fix correctly addresses the issue where entraced errors were showing rlang_error class instead of the original error class. The error_class() function properly unwraps entraced errors to extract the original class.

Potential issue: The comment mentions this approach is "fragile" because entrace() doesn't document the x$error field behavior. Consider adding defensive checks:

error_class <- function(x) {
  # If error was entraced from base R error, use original error class  
  if (inherits(x, "rlang_error") && !is.null(x$error) && inherits(x$error, "condition")) {
    x <- x$error
  }
  class(x)[[1]]
}

This ensures x$error is actually a condition object before unwrapping.

@lionel- lionel- left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good!

@hadley hadley merged commit f920707 into main Jan 7, 2026
13 checks passed
@hadley hadley deleted the base-error branch January 7, 2026 19:23
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.

Error condition provided by expect_snapshot seems buggy in 3.3.0

2 participants