Skip to content

Commit

Permalink
Merge pull request #232 from urbanautomaton/clarify-exception-cause-o…
Browse files Browse the repository at this point in the history
…utput

Clarify output when printing nested exception traces
  • Loading branch information
hsbt committed Oct 24, 2017
2 parents 99f48f2 + f7774e8 commit 920ead3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
17 changes: 13 additions & 4 deletions lib/rake/application.rb
Expand Up @@ -207,13 +207,22 @@ def display_error_message(ex) # :nodoc:
end

def display_exception_details(ex) # :nodoc:
seen = Thread.current[:rake_display_exception_details_seen] ||= []
return if seen.include? ex
seen << ex
display_exception_details_seen << ex

display_exception_message_details(ex)
display_exception_backtrace(ex)
display_exception_details(ex.cause) if has_cause?(ex)
display_cause_details(ex.cause) if has_cause?(ex)
end

def display_cause_details(ex) # :nodoc:
return if display_exception_details_seen.include? ex

trace "\nCaused by:"
display_exception_details(ex)
end

def display_exception_details_seen # :nodoc:
Thread.current[:rake_display_exception_details_seen] ||= []
end

def has_cause?(ex) # :nodoc:
Expand Down
1 change: 1 addition & 0 deletions test/test_rake_application.rb
Expand Up @@ -97,6 +97,7 @@ def test_display_exception_details_cause

assert_empty out

assert_match "Caused by:", err
assert_match "cause a", err
assert_match "cause b", err
end
Expand Down

0 comments on commit 920ead3

Please sign in to comment.