Method: Puppet::Parser::AST#safeevaluate

Defined in:
lib/vendor/puppet/parser/ast.rb

#safeevaluate(*options) ⇒ Object

The version of the evaluate method that should be called, because it correctly handles errors. It is critical to use this method because it can enable you to catch the error where it happens, rather than much higher up the stack.



69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/vendor/puppet/parser/ast.rb', line 69

def safeevaluate(*options)
  # We duplicate code here, rather than using exceptwrap, because this
  # is called so many times during parsing.
  begin
    return self.evaluate(*options)
  rescue Puppet::Error => detail
    raise adderrorcontext(detail)
  rescue => detail
    error = Puppet::Error.new(detail.to_s)
    # We can't use self.fail here because it always expects strings,
    # not exceptions.
    raise adderrorcontext(error, detail)
  end
end