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.



272
273
274
275
# File 'lib/chef/exceptions.rb', line 272

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

Instance Method Details

#client_run_failure(exception) ⇒ Object



284
285
286
287
# File 'lib/chef/exceptions.rb', line 284

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

#empty?Boolean

Returns:

  • (Boolean)


299
300
301
# File 'lib/chef/exceptions.rb', line 299

def empty?
  @all_failures.empty?
end

#for_raiseObject



303
304
305
306
307
308
309
# File 'lib/chef/exceptions.rb', line 303

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

#messageObject



277
278
279
280
281
282
# File 'lib/chef/exceptions.rb', line 277

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



289
290
291
# File 'lib/chef/exceptions.rb', line 289

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

#raise!Object



293
294
295
296
297
# File 'lib/chef/exceptions.rb', line 293

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