Permalink
Browse files

Task invocation chain now printed on errors.

  • Loading branch information...
jimweirich committed May 26, 2009
1 parent 73d55ff commit de46c07c8a014a55584c72833313e969138ced71
Showing with 35 additions and 1 deletion.
  1. +5 −0 Rakefile
  2. +2 −1 lib/rake/application.rb
  3. +5 −0 lib/rake/ext/exception.rb
  4. +16 −0 lib/rake/invocation_exception_mixin.rb
  5. +7 −0 lib/rake/task.rb
View
@@ -412,3 +412,8 @@ desc "Where is the current directory. This task displays\nthe current rake dire
task :where_am_i do
puts Rake.original_dir
end
+
+task :failure => :really_fail
+task :really_fail do
+ fail "oops"
+end
View
@@ -147,8 +147,9 @@ def display_error_message(ex)
$stderr.puts ex.backtrace.join("\n")
else
$stderr.puts ex.backtrace.find {|str| str =~ /#{@rakefile}/ } || ""
- $stderr.puts "(See full trace by running task with --trace)"
end
+ $stderr.puts "Tasks: #{ex.chain}" if ex.chain
+ $stderr.puts "(See full trace by running task with --trace)" unless options.trace
end
# True if one of the files in RAKEFILES is in the current directory.
@@ -0,0 +1,5 @@
+require 'rake/invocation_exception_mixin'
+
+class Exception
+ include Rake::InvocationExceptionMixin
+end
@@ -0,0 +1,16 @@
+module Rake
+ module InvocationExceptionMixin
+ # Return the invocation chain (list of Rake tasks) that were in
+ # effect when this execption was detected by rake. May be null if
+ # no tasks were active.
+ def chain
+ @rake_invocation_chain ||= nil
+ end
+
+ # Set the invocation chain in effect when this exception was
+ # detected.
+ def chain=(value)
+ @rake_invocation_chain = value
+ end
+ end
+end
View
@@ -1,3 +1,5 @@
+require 'rake/ext/exception'
+
module Rake
# #########################################################################
@@ -144,6 +146,11 @@ def invoke_with_call_chain(task_args, invocation_chain) # :nodoc:
invoke_prerequisites(task_args, new_chain)
execute(task_args) if needed?
end
+ rescue Exception => ex
+ if ex.chain.nil?
+ ex.chain = new_chain
+ end
+ raise ex
end
protected :invoke_with_call_chain

0 comments on commit de46c07

Please sign in to comment.