(Improvement): Capture richer rspec exception details#1085
Merged
trunk-io[bot] merged 2 commits intomainfrom May 5, 2026
Merged
(Improvement): Capture richer rspec exception details#1085trunk-io[bot] merged 2 commits intomainfrom
trunk-io[bot] merged 2 commits intomainfrom
Conversation
Use RSpec's ExceptionPresenter for failure_message so customers see what they're used to seeing in their console output: the Failure/Error source line, the exception message, and any "Caused by:" chain. Walk exception.cause for the backtrace field too so root causes aren't dropped, and truncate the middle (instead of the tail) of oversized fields so both the throw site and the project-local frames survive.
|
😎 Merged directly without going through the merge queue, as the queue was empty and the PR was up to date with the target branch - details. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1085 +/- ##
==========================================
+ Coverage 81.75% 82.01% +0.26%
==========================================
Files 69 69
Lines 14917 14917
==========================================
+ Hits 12195 12234 +39
+ Misses 2722 2683 -39 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Collaborator
Author
|
@claude review |
dfrankland
approved these changes
May 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Improving what
rspec_trunk_flaky_testscaptures for failed examples so the data we report matches what users see in their RSpec console output.failure_messagenow delegates toRSpec::Core::Formatters::ExceptionPresenter#fully_formatted(with a no-op colorizer). That gives us the fullFailure/Error: <source line>header, the exception class and message, and anyCaused by:chain — instead of just<class>: <message>. Previously the source line and root-cause chain were silently dropped.backtraceuses RSpec'sformatted_backtrace(which applies the configured backtrace cleaner) and walksexception.causeso each cause's backtrace is appended. This recovers the chained backtraces that Ruby exposes via#causebut that we were ignoring.legacy_format_exception_message/legacy_format_exception_backtrace) and the new code rescuesStandardErrorto fall back if a future RSpec API shift breaks anything, so we still return useful information.Example
RSpec
Failures: 1) multiple_exception_error_test with before hook error and test failure test that would also fail Failure/Error: raise StandardError, 'Error in before hook' StandardError: Error in before hook # ./spec/multiple_exception_spec.rb:7:in `block (3 levels) in <top (required)>' # /home/tyler/repos/analytics-cli/rspec-trunk-flaky-tests/lib/trunk_spec_helper.rb:179:in `run' # /home/tyler/repos/analytics-cli/rspec-trunk-flaky-tests/lib/trunk_spec_helper.rb:149:in `run_with_trunk'Before
More often than not, this backtrace is not useful, and rspec itself natively prettifies/hides it. I did a brief audit of some of our customer traces, and I think this rspec native matching will be preferred. More details below on rollout...
After
Rollout
I plan to confirm this approach works with our end user via a beta release, and go from there. I will also proactively follow-up with our other rspec users to make sure this is not a regression for them. Note that embeddings summaries will certainly drift a bit.
Test plan
failure_messageandbacktrace.causechain (e.g. an error raised from inside a rescue) shows theCaused by:block infailure_messageand the cause's frames inbacktrace.RSpec::Core::MultipleExceptionError(test failure plus anafterhook failure) reports all sub-exceptions.https://claude.ai/code/session_01BHRe4t7dxsGyoMVhLrf3CF
Generated by Claude Code