Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support #detailed_message when task failed #486

Merged
merged 3 commits into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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