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.



327
328
329
330
# File 'lib/chef/exceptions.rb', line 327

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

Instance Method Details

#client_run_failure(exception) ⇒ Object



339
340
341
342
# File 'lib/chef/exceptions.rb', line 339

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

#empty?Boolean

Returns:

  • (Boolean)


354
355
356
# File 'lib/chef/exceptions.rb', line 354

def empty?
  @all_failures.empty?
end

#for_raiseObject



358
359
360
361
362
363
364
# File 'lib/chef/exceptions.rb', line 358

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

#messageObject



332
333
334
335
336
337
# File 'lib/chef/exceptions.rb', line 332

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



344
345
346
# File 'lib/chef/exceptions.rb', line 344

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

#raise!Object



348
349
350
351
352
# File 'lib/chef/exceptions.rb', line 348

def raise!
  unless empty?
    raise for_raise
  end
end