From 76088a6d5712198299ac73a17291fa7a52c796b9 Mon Sep 17 00:00:00 2001 From: Yusuke Endoh Date: Mon, 14 Nov 2022 14:36:24 +0900 Subject: [PATCH] Enable ErrorHighlight for TypeError/ArgumentError only after Ruby 3.2 ... because changing TypeError#message and ArgumentError#message is highly incompatible. --- lib/error_highlight/core_ext.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/error_highlight/core_ext.rb b/lib/error_highlight/core_ext.rb index 00d5671..b69093f 100644 --- a/lib/error_highlight/core_ext.rb +++ b/lib/error_highlight/core_ext.rb @@ -37,6 +37,11 @@ def to_s end NameError.prepend(CoreExt) - TypeError.prepend(CoreExt) - ArgumentError.prepend(CoreExt) + + if Exception.method_defined?(:detailed_message) + # ErrorHighlight is enabled for TypeError and ArgumentError only when Exception#detailed_message is available. + # This is because changing ArgumentError#message is highly incompatible. + TypeError.prepend(CoreExt) + ArgumentError.prepend(CoreExt) + end end