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.


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

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

Instance Method Details

#client_run_failure(exception) ⇒ Object


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

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

#empty?Boolean

Returns:

  • (Boolean)

317
318
319
# File 'lib/chef/exceptions.rb', line 317

def empty?
  @all_failures.empty?
end

#for_raiseObject


321
322
323
324
325
326
327
# File 'lib/chef/exceptions.rb', line 321

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

#messageObject


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

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


307
308
309
# File 'lib/chef/exceptions.rb', line 307

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

#raise!Object


311
312
313
314
315
# File 'lib/chef/exceptions.rb', line 311

def raise!
  unless empty?
    raise for_raise
  end
end