From 857e7e37db850ff0c227cfe241329a7f75b733e6 Mon Sep 17 00:00:00 2001 From: ksss Date: Thu, 30 Mar 2023 10:45:56 +0900 Subject: [PATCH 1/3] Support `#detailed_message` when task failed --- lib/rake/application.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/rake/application.rb b/lib/rake/application.rb index 90f81e109..a8a7d99c1 100644 --- a/lib/rake/application.rb +++ b/lib/rake/application.rb @@ -237,6 +237,8 @@ def has_cause?(ex) # :nodoc: def display_exception_message_details(ex) # :nodoc: if ex.instance_of?(RuntimeError) trace ex.message + elsif ex.respond_to?(:detailed_message) + trace "#{ex.class.name}: #{ex.detailed_message(highlight: false)}" else trace "#{ex.class.name}: #{ex.message}" end From 23d8981dd4fe52f5cc7a09233af469fbbb25c84d Mon Sep 17 00:00:00 2001 From: ksss Date: Thu, 30 Mar 2023 11:31:46 +0900 Subject: [PATCH 2/3] Add testing code for calling `#detailed_message` --- test/test_rake_application.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/test_rake_application.rb b/test/test_rake_application.rb index 8514da354..23fd1a670 100644 --- a/test/test_rake_application.rb +++ b/test/test_rake_application.rb @@ -60,6 +60,33 @@ def test_display_exception_details assert_match __method__.to_s, err end + if Exception.method_defined?(:detailed_message) + def test_display_exception_details_with_detailed_message + error_class = Class.new(StandardError) do + def detailed_message(**) + "detailed_message!!" + end + end + + begin + raise error_class + rescue error_class => ex + end + + out, err = capture_io do + @app.set_default_options # reset trace output IO + + @app.display_error_message ex + end + + assert_empty out + + assert_match "rake aborted!", err + assert_match "detailed_message!!", err + assert_match __method__.to_s, err + end + end + def test_display_exception_details_bad_encoding begin raise "El NiƱo is coming!".dup.force_encoding("US-ASCII") From 6e0b17588935a608d8fdb65691901149fd56a55c Mon Sep 17 00:00:00 2001 From: ksss Date: Thu, 30 Mar 2023 11:40:30 +0900 Subject: [PATCH 3/3] Remove condition minutes as they are unnecessary. --- test/test_rake_application.rb | 36 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/test/test_rake_application.rb b/test/test_rake_application.rb index 23fd1a670..df756a4ad 100644 --- a/test/test_rake_application.rb +++ b/test/test_rake_application.rb @@ -60,31 +60,29 @@ def test_display_exception_details assert_match __method__.to_s, err end - if Exception.method_defined?(:detailed_message) - def test_display_exception_details_with_detailed_message - error_class = Class.new(StandardError) do - def detailed_message(**) - "detailed_message!!" - end + def test_display_exception_details_with_detailed_message + error_class = Class.new(StandardError) do + def detailed_message(**) + "detailed_message!!" end + end - begin - raise error_class - rescue error_class => ex - end + begin + raise error_class + rescue error_class => ex + end - out, err = capture_io do - @app.set_default_options # reset trace output IO + out, err = capture_io do + @app.set_default_options # reset trace output IO - @app.display_error_message ex - end + @app.display_error_message ex + end - assert_empty out + assert_empty out - assert_match "rake aborted!", err - assert_match "detailed_message!!", err - assert_match __method__.to_s, err - end + assert_match "rake aborted!", err + assert_match "detailed_message!!", err + assert_match __method__.to_s, err end def test_display_exception_details_bad_encoding