Skip to content

(Fix): Strip ansi colors from rspec exceptions#1091

Merged
trunk-io[bot] merged 2 commits into
mainfrom
tyler/strip-ansi-colors
May 12, 2026
Merged

(Fix): Strip ansi colors from rspec exceptions#1091
trunk-io[bot] merged 2 commits into
mainfrom
tyler/strip-ansi-colors

Conversation

@TylerJang27
Copy link
Copy Markdown
Collaborator

The recent changes to use the native rspec RSpec::Core::Formatters::ExceptionPresenter were an improvement, but we got a report that it was including ANSI color codes. I was able to repro iff RSpec.configuration.color_mode = :on is set.

Additionally,

We had to strip ANSI codes at the final serialization boundary because PlainColorizer only stops ExceptionPresenter from adding color in its wrap(...) step. RSpec can still inject ANSI earlier when it syntax-highlights the Failure/Error: source snippet, and that path is controlled by global RSpec color settings plus CodeRay, not by our custom colorizer. Since those escapes can already be embedded by the time we format test_output.message and test_output.text, the only reliable fix is to sanitize the final stored strings.

i.e. stripping the codes this way is the safest approach. I was able to repro and verify the fix. Meta note that we're getting to the point where we need a bit more code organization for the rspec gem. I will undertake that when the next fix comes up

@trunk-io
Copy link
Copy Markdown

trunk-io Bot commented May 12, 2026

😎 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.

@TylerJang27
Copy link
Copy Markdown
Collaborator Author

@claude review

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.04%. Comparing base (efb718d) to head (35428e2).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1091      +/-   ##
==========================================
+ Coverage   81.91%   82.04%   +0.12%     
==========================================
  Files          69       69              
  Lines       14939    14939              
==========================================
+ Hits        12237    12256      +19     
+ Misses       2702     2683      -19     

☔ 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-staging-io
Copy link
Copy Markdown

trunk-staging-io Bot commented May 12, 2026

Static BadgeStatic BadgeStatic BadgeStatic Badge

View Full Report ↗︎Docs

@trunk-io
Copy link
Copy Markdown

trunk-io Bot commented May 12, 2026

Static BadgeStatic BadgeStatic BadgeStatic Badge

View Full Report ↗︎Docs

Copy link
Copy Markdown
Member

@dfrankland dfrankland left a comment

Choose a reason for hiding this comment

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

woof

@trunk-io trunk-io Bot merged commit 3c237fa into main May 12, 2026
25 checks passed
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