Skip to content

Commit

Permalink
Merge pull request #486 from ksss/detailed_message
Browse files Browse the repository at this point in the history
Support `#detailed_message` when task failed
  • Loading branch information
hsbt authored Apr 4, 2023
2 parents 45dc937 + 6e0b175 commit 693dcf9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/rake/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions test/test_rake_application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,31 @@ def test_display_exception_details
assert_match __method__.to_s, err
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

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

def test_display_exception_details_bad_encoding
begin
raise "El Niño is coming!".dup.force_encoding("US-ASCII")
Expand Down

0 comments on commit 693dcf9

Please sign in to comment.