Document why UnexpectedNilError inherits from Exception#21
Merged
amomchilov merged 1 commit intomainfrom Mar 4, 2026
Merged
Conversation
Morriar
commented
Mar 4, 2026
amomchilov
reviewed
Mar 4, 2026
Comment on lines
+34
to
+36
| # WARNING: do NOT change the superclass to `StandardError`. | ||
| # Doing so would allow common `rescue StandardError` or bare `rescue` clauses to silently swallow | ||
| # nil errors, masking bugs that should be immediately visible. |
Contributor
There was a problem hiding this comment.
I don't think this is particularly relevant to the gem.
A gem user can't change it unless they make their own copy, which isn't our problem
Suggested change
| # WARNING: do NOT change the superclass to `StandardError`. | |
| # Doing so would allow common `rescue StandardError` or bare `rescue` clauses to silently swallow | |
| # nil errors, masking bugs that should be immediately visible. |
0f89ee8 to
a3ffa4b
Compare
amomchilov
approved these changes
Mar 4, 2026
UnexpectedNilError inherits from Exception
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.
Prompted by a real-world case where a copy of
UnexpectedNilErrorin another codebase changed the superclass toStandardError, which caused nil errors to be silently swallowed by commonrescue StandardErrorclauses in tests — masking bugs that should have been immediately visible.The existing comment explained the rationale but didn't warn against this specific footgun. This PR:
rescue Exceptioncan still catch it (intentionally harder to do accidentally)Related: #20