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.


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

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

Instance Method Details

#client_run_failure(exception) ⇒ Object


309
310
311
312
# File 'lib/chef/exceptions.rb', line 309

def client_run_failure(exception)
  set_backtrace(exception.backtrace)
  @all_failures << [ "#{ChefUtils::Dist::Infra::PRODUCT} run", exception ]
end

#empty?Boolean

Returns:

  • (Boolean)

324
325
326
# File 'lib/chef/exceptions.rb', line 324

def empty?
  @all_failures.empty?
end

#for_raiseObject


328
329
330
331
332
333
334
# File 'lib/chef/exceptions.rb', line 328

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

#messageObject


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

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


314
315
316
# File 'lib/chef/exceptions.rb', line 314

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

#raise!Object


318
319
320
321
322
# File 'lib/chef/exceptions.rb', line 318

def raise!
  unless empty?
    raise for_raise
  end
end