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.



208
209
210
211
# File 'lib/chef/exceptions.rb', line 208

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

Instance Method Details

#client_run_failure(exception) ⇒ Object



220
221
222
223
# File 'lib/chef/exceptions.rb', line 220

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

#empty?Boolean

Returns:

  • (Boolean)


235
236
237
# File 'lib/chef/exceptions.rb', line 235

def empty?
  @all_failures.empty?
end

#for_raiseObject



239
240
241
242
243
244
245
# File 'lib/chef/exceptions.rb', line 239

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

#messageObject



213
214
215
216
217
218
# File 'lib/chef/exceptions.rb', line 213

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



225
226
227
# File 'lib/chef/exceptions.rb', line 225

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

#raise!Object



229
230
231
232
233
# File 'lib/chef/exceptions.rb', line 229

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