Skip to content

Commit a8005fc

Browse files
hsbtclaude
andcommitted
Use Exception#detailed_message hook for lazy loading error enhancer gems
Replace direct gem loading with prepending an Exception::DetailedMessage module that loads the gems on first detailed_message call, then removes itself from the method chain to avoid double dispatch. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 538c28b commit a8005fc

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

gem_prelude.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,16 @@ def self.load
3636
warn "`syntax_suggest' was not loaded."
3737
end if defined?(SyntaxSuggest)
3838
end
39+
end
3940

41+
module Exception::DetailedMessage # :nodoc:
4042
def detailed_message(...)
41-
return super if Ruby::DetailedError.loaded?
4243
Ruby::DetailedError.load
43-
# Re-dispatch to pick up the newly prepended methods from the gems
44+
# Remove this hook so subsequent calls go directly to
45+
# the newly-prepended gem methods without double dispatch.
46+
Exception::DetailedMessage.remove_method(:detailed_message)
4447
detailed_message(...)
4548
end
4649
end
47-
48-
Exception.prepend(Ruby::DetailedError)
50+
Exception.prepend(Exception::DetailedMessage)
4951
end

0 commit comments

Comments
 (0)