Share one KeyError path across rubies with and without detailed_message - #1836
Open
edgibbs wants to merge 1 commit into
Open
Share one KeyError path across rubies with and without detailed_message#1836edgibbs wants to merge 1 commit into
detailed_message#1836edgibbs wants to merge 1 commit into
Conversation
…age` Ruby-version branches, and the two drifted apart: - one emits `"trait".` and `Referenced within` - the other `"trait"` and `referenced within` The specs assert a single format, so 12 fail on Ruby 3.1 and jruby-9.4, and three Layout offenses from the same commit fail `standard`. `main` has been red since 2026-08-21. `did_you_mean` writes its suggestions into `KeyError#message` before Ruby 3.2 and into `#detailed_message` after. Rebuilding the error with the factory's own traits added to the candidates regenerates them on older rubies and returns the message untouched on newer ones, so one implementation serves both and the version conditionals in `Definition` and `Registry` both go away. Dropping `Registry`'s conditional also means every registry miss now carries `key` and `receiver` on older rubies, where they previously raised `ArgumentError`. The 12 specs added by thoughtbot#1824 already cover the message drift; they fail before this change and pass after. Verified with `rake all_specs` on MRI 3.3.6, MRI 3.1.7 and JRuby 9.4.15.0. Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
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
👋 I ran into this while running
bundle exec raketo get a baseline beforepicking up an unrelated issue — the suite fails on a clean checkout of
main.mainhas been red since #1824 merged on 2026-08-21(failing run).
Five jobs fail:
Layout/*offenses#1824 builds the trait-not-found message separately in each of two
Ruby-version branches, and the two drifted apart — one emits
"trait".andReferenced within, the other"trait"andreferenced within. The specsassert a single format, so every ruby taking the second branch fails.
The remaining failure is
traits_spec.rb:497:error_options, added by #1824so did_you_mean can suggest a factory's own traits, was only wired into the
Ruby >= 3.2 branch. On older rubies there was no suggestion data at all.
Why CI didn't catch it
#1824 came from a fork, so its workflow runs needed maintainer approval and
never got it — the PR shows no checks at all. The failure only surfaced on the
post-merge push to
main.The fix
did_you_mean writes its suggestions into
KeyError#messagebefore Ruby 3.2 andinto
#detailed_messageafter. Rebuilding the error with the factory's owntraits added to the candidates regenerates them on older rubies and returns the
message untouched on newer ones — so one implementation serves both, and the
KeyError.method_defined?(:detailed_message)conditionals inDefinitionandRegistryare both deleted rather than repaired. Net −3 lines.Dropping
Registry's conditional also means every registry miss now carrieskeyandreceiveron older rubies, where they previously raisedArgumentError. Messages are unchanged; factory and strategy lookups simplymatch the behaviour they already had on Ruby >= 3.2.
Testing
No new specs. The 12 added by #1824 already cover this — they fail on Ruby 3.1
and jruby-9.4 before this change and pass after. Adding more would duplicate
them.
Verified with
bundle exec rake all_specson:standardclean