Module Puppet::Util::Errors
In: lib/puppet/util/errors.rb

Some helper methods for throwing errors.

Methods

Public Instance methods

Add line and file info if available and appropriate.

[Source]

    # File lib/puppet/util/errors.rb, line 9
 9:     def adderrorcontext(error, other = nil)
10:         error.line ||= self.line if self.respond_to?(:line) and self.line
11:         error.file ||= self.file if self.respond_to?(:file) and self.file
12: 
13:         if other and other.respond_to?(:backtrace)
14:             error.set_backtrace other.backtrace
15:         end
16: 
17:         return error
18:     end

Throw a dev error.

[Source]

   # File lib/puppet/util/errors.rb, line 4
4:     def devfail(msg)
5:         self.fail(Puppet::DevError, msg)
6:     end

Wrap a call in such a way that we always throw the right exception and keep as much context as possible.

[Source]

    # File lib/puppet/util/errors.rb, line 22
22:     def exceptwrap(options = {})
23:         options[:type] ||= Puppet::DevError
24:         begin
25:             return yield
26:         rescue Puppet::Error => detail
27:             raise adderrorcontext(detail)
28:         rescue => detail
29:             message = options[:message] || "%s failed with error %s: %s" %
30:                     [self.class, detail.class, detail.to_s]
31: 
32:             error = options[:type].new(message)
33:             # We can't use self.fail here because it always expects strings,
34:             # not exceptions.
35:             raise adderrorcontext(error, detail)
36:         end
37: 
38:         return retval
39:     end

Throw an error, defaulting to a Puppet::Error.

[Source]

    # File lib/puppet/util/errors.rb, line 42
42:     def fail(*args)
43:         if args[0].is_a?(Class)
44:             type = args.shift
45:         else
46:             type = Puppet::Error
47:         end
48: 
49:         error = adderrorcontext(type.new(args.join(" ")))
50: 
51:         raise error
52:     end

[Validate]