84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
# File 'lib/rescue_each.rb', line 84
def rescue_each(options = {}, &block)
options.assert_valid_keys :method, :args, *RESCUE_EACH_OPTIONS
options.reverse_merge! :method => :each
options.reverse_merge! :args => []
errors = []
retval = __send__ options[:method], *options[:args] do |*args|
begin
block.call(*args.dup)
rescue Exception => e
item = RescueEach::Error::Item.new e, args
if options[:stderr] == :full
$stderr.puts "rescue_each error: #{item}" if options[:stderr]
elsif options[:stderr]
$stderr.puts "rescue_each error: #{item.short_message}"
end
if RescueEach.pass_through_exception? e
if errors.empty?
raise
else
raise e.class, e.message + "\n" + RescueEach::Error.new(errors).to_s
end
end
errors << item
if options[:error_limit] && errors.size >= options[:error_limit]
raise RescueEach::Error.new(errors, true)
end
end
end
raise RescueEach::Error, errors unless errors.empty?
return retval
end
|