Exception: Chef::Exceptions::MultipleFailures

Inherits:
StandardError
  • Object
show all
Defined in:
lib/chef/exceptions.rb

Overview

Exception class for collecting multiple failures. Used when running delayed notifications so that chef can process each delayed notification even if chef client or other notifications fail.

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ MultipleFailures

Returns a new instance of MultipleFailures.



171
172
173
174
# File 'lib/chef/exceptions.rb', line 171

def initialize(*args)
  super
  @all_failures = []
end

Instance Method Details

#client_run_failure(exception) ⇒ Object



183
184
185
186
# File 'lib/chef/exceptions.rb', line 183

def client_run_failure(exception)
  set_backtrace(exception.backtrace)
  @all_failures << [ "chef run", exception ]
end

#empty?Boolean

Returns:

  • (Boolean)


198
199
200
# File 'lib/chef/exceptions.rb', line 198

def empty?
  @all_failures.empty?
end

#for_raiseObject



202
203
204
205
206
207
208
# File 'lib/chef/exceptions.rb', line 202

def for_raise
  if @all_failures.size == 1
    @all_failures[0][1]
  else
    self
  end
end

#messageObject



176
177
178
179
180
181
# File 'lib/chef/exceptions.rb', line 176

def message
  base = "Multiple failures occurred:\n"
  @all_failures.inject(base) do |message, (location, error)|
    message << "* #{error.class} occurred in #{location}: #{error.message}\n"
  end
end

#notification_failure(exception) ⇒ Object



188
189
190
# File 'lib/chef/exceptions.rb', line 188

def notification_failure(exception)
  @all_failures << [ "delayed notification", exception ]
end

#raise!Object



192
193
194
195
196
# File 'lib/chef/exceptions.rb', line 192

def raise!
  unless empty?
    raise self.for_raise
  end
end