lib/lev/errors.rb in lev-4.3.0 vs lib/lev/errors.rb in lev-4.3.1
- old
+ new
@@ -2,16 +2,33 @@
# A collection of Error objects.
#
class Errors < Array
+ def initialize(routine_status = nil, raise_fatal_errors = false)
+ @routine_status = routine_status || BlackHoleStatus.new
+ @raise_fatal_errors = raise_fatal_errors
+ end
+
def add(fail, args={})
args[:kind] ||= :lev
error = Error.new(args)
+
return if ignored_error_procs.any?{|proc| proc.call(error)}
self.push(error)
- throw :fatal_errors_encountered if fail
+
+ routine_status.add_error(error, is_fatal: fail)
+
+ if fail
+ routine_status.failed!
+
+ if raise_fatal_errors
+ raise StandardError, args.to_a.map { |i| i.join(' ') }.join(' - ')
+ else
+ throw :fatal_errors_encountered
+ end
+ end
end
def ignore(arg)
proc = arg.is_a?(Symbol) ?
Proc.new{|error| error.code == arg} :
@@ -34,9 +51,12 @@
def raise_exception_if_any!(exception_type = StandardError)
raise exception_type, collect{|error| error.message}.join('; ') if any?
end
protected
+
+ attr_reader :routine_status
+ attr_reader :raise_fatal_errors
def ignored_error_procs
@ignored_error_procs ||= []
end