Method: Puppet::Util::Errors#adderrorcontext

Defined in:
lib/puppet/util/errors.rb

#adderrorcontext(error, other = nil) ⇒ Exception

Add line and file info to the supplied exception if info is available from this object, is appropriately populated and the supplied exception supports it. When other is supplied, the backtrace will be copied to the error object and the ‘original’ will be dropped from the error.

Parameters:

  • error (Exception)

    exception that is populated with info

  • other (Exception) (defaults to: nil)

    original exception, source of backtrace info

Returns:

  • (Exception)

    error parameter



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/puppet/util/errors.rb', line 22

def adderrorcontext(error, other = nil)
  error.line ||= self.line if error.respond_to?(:line=) and self.respond_to?(:line) and self.line
  error.file ||= self.file if error.respond_to?(:file=) and self.respond_to?(:file) and self.file
  error.original ||= other if error.respond_to?(:original=)

  error.set_backtrace(other.backtrace) if other and other.respond_to?(:backtrace)
  # It is not meaningful to keep the wrapped exception since its backtrace has already
  # been adopted by the error. (The instance variable is private for good reasons).
  error.instance_variable_set(:@original, nil)
  error
end