Propagate exit status in ExecutioError exception

This commit is contained in:
Max Howell 2009-11-06 17:06:12 +00:00
parent 0ec10c68ca
commit 1e879eaee8
4 changed files with 13 additions and 11 deletions

View File

@ -235,7 +235,7 @@ protected
end end
end end
rescue rescue
raise BuildError.new(cmd, args) raise BuildError.new(cmd, args, $?)
end end
private private

View File

@ -57,8 +57,11 @@ HOMEBREW_USER_AGENT = "Homebrew #{HOMEBREW_VERSION} (Ruby #{RUBY_VERSION}-#{RUBY
class ExecutionError <RuntimeError class ExecutionError <RuntimeError
def initialize cmd, args=[] attr :status
def initialize cmd, args=[], status=nil
super "Failure while executing: #{cmd} #{args*' '}" super "Failure while executing: #{cmd} #{args*' '}"
@status = status
end end
end end

View File

@ -86,13 +86,10 @@ def safe_system cmd, *args
puts "#{cmd} #{args*' '}" if ARGV.verbose? puts "#{cmd} #{args*' '}" if ARGV.verbose?
exec_success = Kernel.system cmd, *args exec_success = Kernel.system cmd, *args
# some tools, eg. tar seem to confuse ruby and it doesn't propogate the # some tools, eg. tar seem to confuse ruby and it doesn't propogate the
# CTRL-C interrupt to us too, so execution continues, but the exit code os # CTRL-C interrupt to us too, so execution continues, but the exit code is
# still 2 so we raise our own interrupt # still 2 so we raise our own interrupt
raise Interrupt, cmd if $?.termsig == 2 raise Interrupt, cmd if $?.termsig == 2
unless exec_success raise ExecutionError.new(cmd, args, $?) unless exec_success
puts "Exit code: #{$?}"
raise ExecutionError.new(cmd, args)
end
end end
def curl *args def curl *args
@ -146,7 +143,6 @@ def arch_for_command cmd
return archs return archs
end end
# replaces before with after for the file path # replaces before with after for the file path
def inreplace path, before, after def inreplace path, before, after
f = File.open(path, 'r') f = File.open(path, 'r')

View File

@ -70,8 +70,8 @@ EOS
end end
def please_report_bug; <<-EOS def please_report_bug; <<-EOS
Please report this bug to #{HOMEBREW_WWW} including the following information: Please report this bug to #{HOMEBREW_WWW}
Mac OS X: #{MACOS_VERSION} Mac OS X: #{MACOS_FULL_VERSION}
Ponk: #{macports_or_fink_installed?} Ponk: #{macports_or_fink_installed?}
EOS EOS
end end
@ -263,7 +263,10 @@ rescue SystemCallError, RuntimeError => e
puts e.backtrace puts e.backtrace
else else
onoe e onoe e
puts please_report_bug if e.kind_of? BuildError if e.kind_of? BuildError
puts please_report_bug
puts "Exit Status: #{e.status}"
end
end end
exit 1 exit 1
rescue Exception => e rescue Exception => e