Skip to content

(Improvement): Capture richer rspec exception details#1085

Open
TylerJang27 wants to merge 1 commit intomainfrom
claude/debug-rspec-nil-error-fm9yD
Open

(Improvement): Capture richer rspec exception details#1085
TylerJang27 wants to merge 1 commit intomainfrom
claude/debug-rspec-nil-error-fm9yD

Conversation

@TylerJang27
Copy link
Copy Markdown
Collaborator

Summary

Improving what rspec_trunk_flaky_tests captures for failed examples so the data we report matches what users see in their RSpec console output.

  • failure_message now delegates to RSpec::Core::Formatters::ExceptionPresenter#fully_formatted (with a no-op colorizer). That gives us the full Failure/Error: <source line> header, the exception class and message, and any Caused by: chain — instead of just <class>: <message>. Previously the source line and root-cause chain were silently dropped.
  • backtrace uses RSpec's formatted_backtrace (which applies the configured backtrace cleaner) and walks exception.cause so each cause's backtrace is appended. This recovers the chained backtraces that Ruby exposes via #cause but that we were ignoring.
  • Truncation now drops characters from the middle of an over-budget field instead of chopping the tail. The head usually carries the exception class/message and the tail usually carries the project-local frames; either alone is much less useful than both with a marker in between. Cuts are aligned to line boundaries so output stays readable.
  • The previous formatting paths are preserved as fallbacks (legacy_format_exception_message / legacy_format_exception_backtrace) and the new code rescues StandardError to fall back if a future RSpec API shift breaks anything, so we don't regress existing behavior.

Test plan

  • Verify a test that fails with a plain assertion still produces a clean failure_message and backtrace.
  • Verify a test whose failure has a cause chain (e.g. an error raised from inside a rescue) shows the Caused by: block in failure_message and the cause's frames in backtrace.
  • Verify a test that fails with RSpec::Core::MultipleExceptionError (test failure plus an after hook failure) reports all sub-exceptions.
  • Verify an oversized backtrace gets middle-truncated with both the throw-site frames and the project frames preserved.
  • Confirm bundles upload successfully end-to-end.

https://claude.ai/code/session_01BHRe4t7dxsGyoMVhLrf3CF


Generated by Claude Code

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.
@trunk-io
Copy link
Copy Markdown

trunk-io Bot commented Apr 30, 2026

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@trunk-staging-io
Copy link
Copy Markdown

trunk-staging-io Bot commented Apr 30, 2026

Static BadgeStatic BadgeStatic BadgeStatic Badge

View Full Report ↗︎Docs

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 30, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.01%. Comparing base (a5dce4e) to head (d6dea80).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@trunk-io
Copy link
Copy Markdown

trunk-io Bot commented Apr 30, 2026

Static BadgeStatic BadgeStatic BadgeStatic Badge

View Full Report ↗︎Docs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants