lib/autobuild/reporting.rb in autobuild-1.11.2 vs lib/autobuild/reporting.rb in autobuild-1.12.0
- old
+ new
@@ -44,11 +44,13 @@
if args.empty? then ""
else "#{color(*args)}"
end
if !Autobuild.progress_display_enabled?
- io.puts msg
+ if !silent?
+ io.puts msg
+ end
return
end
size =
if @last_progress_msg then @last_progress_msg.size
@@ -268,51 +270,91 @@
end
result.join("\n")
end
end
- ## The reporting module provides the framework
- # to run commands in autobuild and report errors
- # to the user
+ ## The reporting module provides the framework # to run commands in
+ # autobuild and report errors # to the user
#
# It does not use a logging framework like Log4r, but it should ;-)
module Reporting
@@reporters = Array.new
## Run a block and report known exception
# If an exception is fatal, the program is terminated using exit()
- def self.report
+ def self.report(on_package_failures: default_report_on_package_failures)
begin yield
- rescue Interrupt
- interrupted = true
+ rescue Interrupt => e
+ interrupted = e
+ rescue Autobuild::Exception => e
+ return report_finish_on_error([e], on_package_failures: on_package_failures, interrupted_by: interrupted)
end
# If ignore_erorrs is true, check if some packages have failed
# on the way. If so, raise an exception to inform the user about
# it
errors = []
Autobuild::Package.each do |name, pkg|
errors.concat(pkg.failures)
end
- if !errors.empty?
- raise CompositeException.new(errors)
- elsif interrupted
- raise Interrupt
+ report_finish_on_error(errors, on_package_failures: on_package_failures, interrupted_by: interrupted)
+ end
+
+ # @api private
+ #
+ # Helper that returns the default for on_package_failures
+ #
+ # The result depends on the value for Autobuild.debug. It is either
+ # :exit if debug is false, or :raise if it is true
+ def self.default_report_on_package_failures
+ if Autobuild.debug then :raise
+ else :exit
end
+ end
- rescue Autobuild::Exception => e
- error(e)
- if e.fatal?
- if Autobuild.debug
- raise
+ # @api private
+ #
+ # Handle how Reporting.report is meant to finish in case of error(s)
+ #
+ # @param [Symbol] on_package_failures how does the reporting should behave.
+ #
+ def self.report_finish_on_error(errors, on_package_failures: default_report_on_package_failures, interrupted_by: nil)
+ if ![:raise, :report_silent, :exit_silent].include?(on_package_failures)
+ errors.each { |e| error(e) }
+ end
+ fatal = errors.any?(&:fatal?)
+ if !fatal
+ if interrupted_by
+ raise interrupted_by
else
- exit 1
+ return errors
end
end
+
+ if on_package_failures == :raise
+ if interrupted_by
+ raise interrupted_by
+ end
+
+ e = if errors.size == 1 then errors.first
+ else CompositeException.new(errors)
+ end
+ raise e
+ elsif [:report_silent, :report].include?(on_package_failures)
+ if interrupted_by
+ raise interrupted_by
+ else
+ return errors
+ end
+ elsif [:exit, :exit_silent].include?(on_package_failures)
+ exit 1
+ else
+ raise ArgumentError, "unexpected value for on_package_failures: #{on_package_failures}"
+ end
end
-
+
## Reports a successful build to the user
def self.success
each_reporter { |rep| rep.success }
end
@@ -332,13 +374,13 @@
def self.clear_reporters
@@reporters.clear
end
- def self.each_reporter(&iter)
- @@reporters.each(&iter)
- end
+ def self.each_reporter(&iter)
+ @@reporters.each(&iter)
+ end
## Iterate on all log files
def self.each_log(&block)
Autobuild.logfiles.each(&block)
end
@@ -361,6 +403,5 @@
puts Autobuild.post_success_message
end
end
end
end
-