diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-01-18 17:24:15 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-01-18 17:24:15 +0000 |
| commit | 6bab167dcbb274fd302a65d567d6af0ef6621b79 (patch) | |
| tree | 92093e971bab20400ac8218a5cf1b159e64b5cbb /lib/puppet/parser | |
| parent | ed39be9dd2ecdbe9a8624ed2f6c03334e123e81d (diff) | |
| download | puppet-6bab167dcbb274fd302a65d567d6af0ef6621b79.tar.gz puppet-6bab167dcbb274fd302a65d567d6af0ef6621b79.tar.xz puppet-6bab167dcbb274fd302a65d567d6af0ef6621b79.zip | |
Made lots of small changes, mostly to help usability but also fixed a couple of key bugs
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@841 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet/parser')
| -rw-r--r-- | lib/puppet/parser/ast.rb | 27 | ||||
| -rw-r--r-- | lib/puppet/parser/ast/astarray.rb | 3 | ||||
| -rw-r--r-- | lib/puppet/parser/ast/classdef.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/parser/ast/compdef.rb | 4 | ||||
| -rw-r--r-- | lib/puppet/parser/ast/component.rb | 7 | ||||
| -rw-r--r-- | lib/puppet/parser/ast/leaf.rb | 7 | ||||
| -rw-r--r-- | lib/puppet/parser/ast/nodedef.rb | 5 | ||||
| -rw-r--r-- | lib/puppet/parser/ast/objectdef.rb | 52 | ||||
| -rw-r--r-- | lib/puppet/parser/ast/objectref.rb | 20 | ||||
| -rw-r--r-- | lib/puppet/parser/ast/typedefaults.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/parser/ast/vardef.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/parser/grammar.ra | 18 | ||||
| -rw-r--r-- | lib/puppet/parser/interpreter.rb | 10 | ||||
| -rw-r--r-- | lib/puppet/parser/parser.rb | 26 | ||||
| -rw-r--r-- | lib/puppet/parser/scope.rb | 45 |
15 files changed, 111 insertions, 119 deletions
diff --git a/lib/puppet/parser/ast.rb b/lib/puppet/parser/ast.rb index 9854b5d34..c8cc74f04 100644 --- a/lib/puppet/parser/ast.rb +++ b/lib/puppet/parser/ast.rb @@ -58,19 +58,24 @@ module Puppet def safeevaluate(*args) begin self.evaluate(*args) - rescue Puppet::DevError + rescue Puppet::DevError => except + except.line ||= @line + except.file ||= @file raise - rescue Puppet::ParseError + rescue Puppet::ParseError => except + except.line ||= @line + except.file ||= @file raise rescue => detail if Puppet[:debug] - puts caller + puts detail.backtrace end error = Puppet::DevError.new( "Child of type %s failed with error %s: %s" % [self.class, detail.class, detail.to_s] ) - error.stack = caller + error.line ||= @line + error.file ||= @file raise error end end @@ -83,23 +88,22 @@ module Puppet "(" + self.class.to_s.sub(/.+::/,'') + ")" end - # Initialize the object. Requires a hash as the argument, and takes - # each of the parameters of the hash and calls the settor method for - # them. This is probably pretty inefficient and should likely be changed - # at some point. + # Initialize the object. Requires a hash as the argument, and + # takes each of the parameters of the hash and calls the settor + # method for them. This is probably pretty inefficient and should + # likely be changed at some point. def initialize(args) @file = nil @line = nil args.each { |param,value| method = param.to_s + "=" unless self.respond_to?(method) - error = Puppet::DevError.new( + error = Puppet::ParseError.new( "Invalid parameter %s to object class %s" % [param,self.class.to_s] ) error.line = self.line error.file = self.file - error.stack = caller raise error end @@ -111,7 +115,8 @@ module Puppet "Could not set parameter %s on class %s: %s" % [method,self.class.to_s,detail] ) - error.stack = caller + error.line ||= self.line + error.file ||= self.file raise error end } diff --git a/lib/puppet/parser/ast/astarray.rb b/lib/puppet/parser/ast/astarray.rb index 3a02c58ea..1e7bdb81c 100644 --- a/lib/puppet/parser/ast/astarray.rb +++ b/lib/puppet/parser/ast/astarray.rb @@ -43,7 +43,10 @@ class Puppet::Parser::AST item.safeevaluate(scope) } end + rets = rets.reject { |obj| obj.nil? } + + return rets end def push(*ary) diff --git a/lib/puppet/parser/ast/classdef.rb b/lib/puppet/parser/ast/classdef.rb index b9f1c1c6b..7386b25eb 100644 --- a/lib/puppet/parser/ast/classdef.rb +++ b/lib/puppet/parser/ast/classdef.rb @@ -47,7 +47,7 @@ class Puppet::Parser::AST error = Puppet::ParseError.new(detail) error.line = self.line error.file = self.file - error.stack = caller + error.backtrace = detail.backtrace raise error end end diff --git a/lib/puppet/parser/ast/compdef.rb b/lib/puppet/parser/ast/compdef.rb index ffd0dc0e0..4118c7184 100644 --- a/lib/puppet/parser/ast/compdef.rb +++ b/lib/puppet/parser/ast/compdef.rb @@ -36,7 +36,7 @@ class Puppet::Parser::AST error = Puppet::ParseError.new(detail) error.line = self.line error.file = self.file - error.stack = caller + error.backtrace = detail.backtrace raise error end end @@ -45,7 +45,7 @@ class Puppet::Parser::AST @parentclass = nil super - Puppet.debug "Defining type %s" % @name.value + #Puppet.debug "Defining type %s" % @name.value # we need to both mark that a given argument is valid, # and we need to also store any provided default arguments diff --git a/lib/puppet/parser/ast/component.rb b/lib/puppet/parser/ast/component.rb index f1e6b9648..841977b2f 100644 --- a/lib/puppet/parser/ast/component.rb +++ b/lib/puppet/parser/ast/component.rb @@ -48,8 +48,8 @@ class Puppet::Parser::AST unless hash.include?(arg) if defined? default and ! default.nil? hash[arg] = default - Puppet.debug "Got default %s for %s in %s" % - [default.inspect, arg.inspect, objname.inspect] + #Puppet.debug "Got default %s for %s in %s" % + # [default.inspect, arg.inspect, objname.inspect] else error = Puppet::ParseError.new( "Must pass %s to %s of type %s" % @@ -57,7 +57,6 @@ class Puppet::Parser::AST ) error.line = self.line error.file = self.file - error.stack = caller raise error end end @@ -82,7 +81,7 @@ class Puppet::Parser::AST error = Puppet::ParseError.new(except.message) error.line = self.line error.file = self.file - error.stack = caller + error.backtrace = except.backtrace raise error end } diff --git a/lib/puppet/parser/ast/leaf.rb b/lib/puppet/parser/ast/leaf.rb index 53cefdeb3..d25527864 100644 --- a/lib/puppet/parser/ast/leaf.rb +++ b/lib/puppet/parser/ast/leaf.rb @@ -29,11 +29,8 @@ class Puppet::Parser::AST super unless @value == 'true' or @value == 'false' - error = Puppet::DevError.new( + raise Puppet::DevError, "'%s' is not a boolean" % @value - ) - error.stack = caller - raise error end if @value == 'true' @value = true @@ -80,7 +77,7 @@ class Puppet::Parser::AST error = Puppet::DevError.new(detail) error.line = self.line error.file = self.file - error.stack = caller + error.backtrace = detail.backtrace raise error end end diff --git a/lib/puppet/parser/ast/nodedef.rb b/lib/puppet/parser/ast/nodedef.rb index 1cd0f683e..c0e1ee63e 100644 --- a/lib/puppet/parser/ast/nodedef.rb +++ b/lib/puppet/parser/ast/nodedef.rb @@ -18,8 +18,8 @@ class Puppet::Parser::AST end names.each { |name| - Puppet.debug("defining host '%s' in scope %s" % - [name, scope.object_id]) + #Puppet.debug("defining host '%s' in scope %s" % + # [name, scope.object_id]) arghash = { :name => name, :code => @code @@ -41,7 +41,6 @@ class Puppet::Parser::AST error = Puppet::ParseError.new(detail) error.line = self.line error.file = self.file - error.stack = caller raise error end } diff --git a/lib/puppet/parser/ast/objectdef.rb b/lib/puppet/parser/ast/objectdef.rb index 05be941ac..8999e921d 100644 --- a/lib/puppet/parser/ast/objectdef.rb +++ b/lib/puppet/parser/ast/objectdef.rb @@ -63,25 +63,24 @@ class Puppet::Parser::AST error = Puppet::ParseError.new(detail) error.line = self.line error.file = self.file - error.stack = caller + error.backtrace = detail.backtrace raise error end unless object # If not, verify that it's a builtin type - begin - object = Puppet::Type.type(objtype) - rescue TypeError - # otherwise, the user specified an invalid type - error = Puppet::ParseError.new( - "Invalid type %s" % objtype - ) - error.line = @line - error.file = @file + object = Puppet::Type.type(objtype) + + # Type.type returns nil on object types that aren't found + unless object + error = Puppet::ParseError.new("Invalid type %s" % objtype) + error.line = self.line + error.file = self.file raise error end end + # Autogenerate the name if one was not passed. if defined? @name objnames = @name.safeevaluate(scope) @@ -110,12 +109,12 @@ class Puppet::Parser::AST # If the object is a class, that means it's a builtin type if object.is_a?(Class) begin - Puppet.debug( - ("Setting object '%s' " + - "in scope %s " + - "with arguments %s") % - [objname, scope.object_id, hash.inspect] - ) + #Puppet.debug( + # ("Setting object '%s' " + + # "in scope %s " + + # "with arguments %s") % + # [objname, scope.object_id, hash.inspect] + #) obj = scope.setobject( objtype, objname, @@ -131,14 +130,14 @@ class Puppet::Parser::AST error = Puppet::ParseError.new(detail) error.line = self.line error.file = self.file - error.stack = caller + error.backtrace = detail.backtrace raise error end else # but things like components create a new type; if we find # one of those, evaluate that with our arguments - Puppet.debug("Calling object '%s' with arguments %s" % - [object.name, hash.inspect]) + #Puppet.debug("Calling object '%s' with arguments %s" % + # [object.name, hash.inspect]) object.safeevaluate(scope,hash,objtype,objname) end }.reject { |obj| obj.nil? } @@ -150,8 +149,8 @@ class Puppet::Parser::AST begin defaults = scope.lookupdefaults(objtype) if defaults.length > 0 - Puppet.debug "Got defaults for %s: %s" % - [objtype,defaults.inspect] + #Puppet.debug "Got defaults for %s: %s" % + # [objtype,defaults.inspect] end rescue => detail raise Puppet::DevError, @@ -219,7 +218,6 @@ class Puppet::Parser::AST "Invalid parameter '%s' for type '%s'" % [pname,type.name] ) - error.stack = caller error.line = self.line error.file = self.file raise error @@ -243,7 +241,6 @@ class Puppet::Parser::AST "Invalid parameter '%s' for type '%s'" % [pname,objtype] ) - error.stack = caller error.line = self.line error.file = self.file raise error @@ -277,7 +274,7 @@ class Puppet::Parser::AST error = Puppet::DevError.new( "failed to tree a %s" % self.class ) - error.stack = caller + error.backtrace = detail.backtrace raise error end }.join("\n") @@ -306,13 +303,12 @@ class Puppet::Parser::AST ) error.line = self.line error.file = self.file - error.stack = caller raise error end - unless builtin - Puppet.debug "%s is a defined type" % objtype - end + #unless builtin + # Puppet.debug "%s is a defined type" % objtype + #end self.paramcheck(builtin, objtype) diff --git a/lib/puppet/parser/ast/objectref.rb b/lib/puppet/parser/ast/objectref.rb index e9561d65d..6418c14fb 100644 --- a/lib/puppet/parser/ast/objectref.rb +++ b/lib/puppet/parser/ast/objectref.rb @@ -21,7 +21,7 @@ class Puppet::Parser::AST objnames = [objnames] end - # Verify we can find the object. + # See if we can look the object up in our scope tree. begin object = scope.lookuptype(objtype) rescue Puppet::ParseError => except @@ -32,20 +32,32 @@ class Puppet::Parser::AST error = Puppet::ParseError.new(detail) error.line = self.line error.file = self.file - error.stack = caller + error.backtrace = detail.backtrace + raise error + end + + # If the type isn't defined, verify that it's builtin + unless object or Puppet::Type.type(objtype) + error = Puppet::ParseError.new("Could not find type %s" % + objtype.inspect) + error.line = self.line + error.file = self.file raise error end - Puppet.debug "ObjectRef returned type %s" % object # should we implicitly iterate here? # yes, i believe that we essentially have to... - objnames.collect { |objname| + ret = objnames.collect { |objname| if object.is_a?(AST::Component) objname = "%s[%s]" % [objtype,objname] objtype = "component" end [objtype,objname] }.reject { |obj| obj.nil? } + + # Return a flattened array, since we know that we've created an + # array + return *ret end def tree(indent = 0) diff --git a/lib/puppet/parser/ast/typedefaults.rb b/lib/puppet/parser/ast/typedefaults.rb index 17ef94589..c1f8cce52 100644 --- a/lib/puppet/parser/ast/typedefaults.rb +++ b/lib/puppet/parser/ast/typedefaults.rb @@ -24,7 +24,7 @@ class Puppet::Parser::AST error = Puppet::ParseError.new(detail) error.line = self.line error.file = self.file - error.stack = caller + error.backtrace = detail.backtrace raise error end end diff --git a/lib/puppet/parser/ast/vardef.rb b/lib/puppet/parser/ast/vardef.rb index 6ada75589..52548a42c 100644 --- a/lib/puppet/parser/ast/vardef.rb +++ b/lib/puppet/parser/ast/vardef.rb @@ -19,7 +19,7 @@ class Puppet::Parser::AST error = Puppet::ParseError.new(detail) error.line = self.line error.file = self.file - error.stack = caller + error.backtrace = detail.backtrace raise error end end diff --git a/lib/puppet/parser/grammar.ra b/lib/puppet/parser/grammar.ra index 469bb5dee..3630d27ef 100644 --- a/lib/puppet/parser/grammar.ra +++ b/lib/puppet/parser/grammar.ra @@ -662,8 +662,11 @@ array: LBRACK rvalues RBRACK { if val[1].is_a?(AST::ASTArray) result = val[1] else - result = AST::ASTArray.new - result.push val[1] + result = AST::ASTArray.new( + :line => @lexer.line, + :file => @lexer.file, + :children => [val[1]] + ) end } @@ -682,10 +685,7 @@ require 'puppet/parser/ast' #require 'puppet/parser/interpreter' module Puppet - # this exception class already has a :stack accessor - class ParseError < Puppet::Error - attr_accessor :line, :file - end + class ParseError < Puppet::Error; end class ImportError < Racc::ParseError; end end @@ -764,7 +764,7 @@ def parse error = Puppet::ParseError.new(except) error.line = @lexer.line error.file = @lexer.file - error.stack = caller + error.backtrace = except.backtrace raise error rescue Puppet::ParseError => except except.line ||= @lexer.line @@ -774,7 +774,6 @@ def parse # and this is a framework error except.line ||= @lexer.line except.file ||= @lexer.file - except.stack ||= except.stack #if Puppet[:debug] # puts except.stack #end @@ -782,7 +781,6 @@ def parse rescue Puppet::DevError => except except.line ||= @lexer.line except.file ||= @lexer.file - except.stack ||= caller #if Puppet[:debug] # puts except.stack #end @@ -791,7 +789,7 @@ def parse error = Puppet::DevError.new(except.message) error.line = @lexer.line error.file = @lexer.file - error.stack = caller + error.backtrace = except.backtrace #if Puppet[:debug] # puts caller #end diff --git a/lib/puppet/parser/interpreter.rb b/lib/puppet/parser/interpreter.rb index 96555faa1..b1cf4207c 100644 --- a/lib/puppet/parser/interpreter.rb +++ b/lib/puppet/parser/interpreter.rb @@ -82,19 +82,15 @@ module Puppet #Puppet.err "File %s, line %s: %s" % # [except.file, except.line, except.message] if Puppet[:debug] - puts except.stack - end - if Puppet[:debug] - puts caller + puts except.backtrace end #exit(1) raise rescue => except error = Puppet::DevError.new("%s: %s" % [except.class, except.message]) - error.stack = caller if Puppet[:debug] - puts caller + puts except.backtrace end raise error end @@ -111,6 +107,8 @@ module Puppet # entire configuration each time we get a connect. def evaluate + # FIXME When this produces errors, it should specify which + # node caused those errors. if @usenodes @scope = Puppet::Parser::Scope.new() # no parent scope @scope.name = "top" diff --git a/lib/puppet/parser/parser.rb b/lib/puppet/parser/parser.rb index c50e65cac..582283704 100644 --- a/lib/puppet/parser/parser.rb +++ b/lib/puppet/parser/parser.rb @@ -14,10 +14,7 @@ require 'puppet/parser/ast' #require 'puppet/parser/interpreter' module Puppet - # this exception class already has a :stack accessor - class ParseError < Puppet::Error - attr_accessor :line, :file - end + class ParseError < Puppet::Error; end class ImportError < Racc::ParseError; end end @@ -32,7 +29,7 @@ module Puppet class Parser < Racc::Parser -module_eval <<'..end grammar.ra modeval..id082f0a899d', 'grammar.ra', 697 +module_eval <<'..end grammar.ra modeval..idc16574e75e', 'grammar.ra', 697 attr_reader :file attr_accessor :files @@ -103,7 +100,7 @@ def parse error = Puppet::ParseError.new(except) error.line = @lexer.line error.file = @lexer.file - error.stack = caller + error.backtrace = except.backtrace raise error rescue Puppet::ParseError => except except.line ||= @lexer.line @@ -113,7 +110,6 @@ def parse # and this is a framework error except.line ||= @lexer.line except.file ||= @lexer.file - except.stack ||= except.stack #if Puppet[:debug] # puts except.stack #end @@ -121,7 +117,6 @@ def parse rescue Puppet::DevError => except except.line ||= @lexer.line except.file ||= @lexer.file - except.stack ||= caller #if Puppet[:debug] # puts except.stack #end @@ -130,7 +125,7 @@ def parse error = Puppet::DevError.new(except.message) error.line = @lexer.line error.file = @lexer.file - error.stack = caller + error.backtrace = except.backtrace #if Puppet[:debug] # puts caller #end @@ -149,7 +144,7 @@ def string=(string) end # $Id$ -..end grammar.ra modeval..id082f0a899d +..end grammar.ra modeval..idc16574e75e ##### racc 1.4.4 generates ### @@ -1404,13 +1399,16 @@ module_eval <<'.,.,', 'grammar.ra', 659 end .,., -module_eval <<'.,.,', 'grammar.ra', 668 +module_eval <<'.,.,', 'grammar.ra', 671 def _reduce_90( val, _values, result ) if val[1].is_a?(AST::ASTArray) result = val[1] else - result = AST::ASTArray.new - result.push val[1] + result = AST::ASTArray.new( + :line => @lexer.line, + :file => @lexer.file, + :children => [val[1]] + ) end result end @@ -1422,7 +1420,7 @@ module_eval <<'.,.,', 'grammar.ra', 668 # reduce 93 omitted -module_eval <<'.,.,', 'grammar.ra', 673 +module_eval <<'.,.,', 'grammar.ra', 676 def _reduce_94( val, _values, result ) result = nil result diff --git a/lib/puppet/parser/scope.rb b/lib/puppet/parser/scope.rb index 598c67b5e..c2c59fc5a 100644 --- a/lib/puppet/parser/scope.rb +++ b/lib/puppet/parser/scope.rb @@ -360,7 +360,6 @@ module Puppet "Could not retrieve %s table at level %s" % [type,self.level] ) - error.stack = caller raise error end @@ -412,32 +411,32 @@ module Puppet # Look up a node by name def lookupnode(name) - Puppet.debug "Looking up type %s" % name + #Puppet.debug "Looking up type %s" % name value = self.lookup("type",name) if value == :undefined return nil else - Puppet.debug "Found type %s" % name + #Puppet.debug "Found node %s" % name return value end end # Look up a defined type. def lookuptype(name) - Puppet.debug "Looking up type %s" % name + #Puppet.debug "Looking up type %s" % name value = self.lookup("type",name) if value == :undefined return nil else - Puppet.debug "Found type %s" % name + #Puppet.debug "Found type %s" % name return value end end # Look up an object by name and type. def lookupobject(name,type) - Puppet.debug "Looking up object %s of type %s in level %s" % - [name, type, @level] + #Puppet.debug "Looking up object %s of type %s in level %s" % + # [name, type, @level] sub = proc { |table| if table.include?(type) if table[type].include?(name) @@ -457,13 +456,12 @@ module Puppet # Look up a variable. The simplest value search we do. def lookupvar(name) - Puppet.debug "Looking up variable %s" % name + #Puppet.debug "Looking up variable %s" % name value = self.lookup("variable", name) if value == :undefined error = Puppet::ParseError.new( "Undefined variable '%s'" % name ) - error.stack = caller raise error else #Puppet.debug "Value of '%s' is '%s'" % [name,value] @@ -473,7 +471,7 @@ module Puppet # Create a new scope. def newscope - Puppet.debug "Creating new scope, level %s" % [self.level + 1] + #Puppet.debug "Creating new scope, level %s" % [self.level + 1] return Puppet::Parser::Scope.new(self) end @@ -498,15 +496,14 @@ module Puppet end params.each { |ary| - Puppet.debug "Default for %s is %s => %s" % - [type,ary[0].inspect,ary[1].inspect] + #Puppet.debug "Default for %s is %s => %s" % + # [type,ary[0].inspect,ary[1].inspect] if @@declarative if table.include?(ary[0]) error = Puppet::ParseError.new( "Default already defined for %s { %s }" % [type,ary[0]] ) - error.stack = caller raise error end else @@ -601,14 +598,10 @@ module Puppet # in scopes above, but will not allow variables in the current scope # to be reassigned if we're declarative (which is the default). def setvar(name,value) - Puppet.debug "Setting %s to '%s' at level %s" % - [name.inspect,value,self.level] + #Puppet.debug "Setting %s to '%s' at level %s" % + # [name.inspect,value,self.level] if @@declarative and @symtable.include?(name) - error = Puppet::ParseError.new( - "Cannot reassign variable %s" % name - ) - error.stack = caller - raise error + raise Puppet::ParseError, "Cannot reassign variable %s" % name else if @symtable.include?(name) Puppet.warning "Reassigning %s to %s" % [name,value] @@ -699,12 +692,9 @@ module Puppet @topscope.addtags(child) results.push(child) else - error = Puppet::DevError.new( + raise Puppet::DevError, "Puppet::Parse::Scope cannot handle objects of type %s" % child.class - ) - error.stack = caller - raise error end } @@ -728,11 +718,8 @@ module Puppet if defined? @type bucket.type = @type else - error = Puppet::ParseError.new( + raise Puppet::ParseError, "No type for scope %s" % @name - ) - error.stack = caller - raise error end #Puppet.debug( # "TransBucket with name %s and type %s in scope %s" % @@ -752,7 +739,7 @@ module Puppet # [bucket.name,self.object_id] return bucket else - Puppet.debug "nameless scope; just returning a list" + #Puppet.debug "nameless scope; just returning a list" return results end end |
