Skip to content

Commit da05823

Browse files
authored
Merge pull request #21 from Shopify/Alex/document-exception-inheritance
Document why UnexpectedNilError inherits from Exception and warn against changing it
2 parents 998651d + a3ffa4b commit da05823

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

lib/type_toolkit/ext/nil_assertions.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ module TypeToolkit
2727
#
2828
# `UnexpectedNilError` should never occur in well-formed code, so it should never be rescued.
2929
# This is why it inherits from `Exception` instead of `StandardError`,
30-
# so that bare rescues clauses (like `rescue => e`) don't rescue it.
30+
# so that bare rescue clauses (like `rescue => e`) don't accidentally swallow it.
31+
#
32+
# Note: `rescue Exception` can still catch it, but that's intentionally harder to write accidentally.
3133
class UnexpectedNilError < Exception # rubocop:disable Lint/InheritException
3234
def initialize(message = "Called `not_nil!` on nil.")
3335
super

0 commit comments

Comments
 (0)