From a3ffa4b5ec40c824cc1b433fdf1a7373b2997f80 Mon Sep 17 00:00:00 2001 From: Alexandre Terrasa Date: Wed, 4 Mar 2026 13:49:20 -0500 Subject: [PATCH] Document why UnexpectedNilError inherits from Exception and warn against changing it --- lib/type_toolkit/ext/nil_assertions.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/type_toolkit/ext/nil_assertions.rb b/lib/type_toolkit/ext/nil_assertions.rb index b36900d..c444046 100644 --- a/lib/type_toolkit/ext/nil_assertions.rb +++ b/lib/type_toolkit/ext/nil_assertions.rb @@ -27,7 +27,9 @@ module TypeToolkit # # `UnexpectedNilError` should never occur in well-formed code, so it should never be rescued. # This is why it inherits from `Exception` instead of `StandardError`, - # so that bare rescues clauses (like `rescue => e`) don't rescue it. + # so that bare rescue clauses (like `rescue => e`) don't accidentally swallow it. + # + # Note: `rescue Exception` can still catch it, but that's intentionally harder to write accidentally. class UnexpectedNilError < Exception # rubocop:disable Lint/InheritException def initialize(message = "Called `not_nil!` on nil.") super