[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, upstream, updated. 0.25.5-639-g8f94f35

James Turnbull james at lovedthanlost.net
Wed Jul 14 10:29:29 UTC 2010


The following commit has been merged in the upstream branch:
commit 391786f0b43e514d58336f465bc53fb7a5c34884
Author: Brice Figureau <brice-puppet at daysofwonder.com>
Date:   Tue Nov 10 17:57:26 2009 +0100

    Fix #2795 - puppetdoc rdoc reports a better error message
    
    When puppetdoc rdoc dies with an unhandled exception, the error
    message produced didn't mention the file and line where the parser
    choked.
    This patch fixes this by trying to locate on which AST structure
    the rdoc system failed.
    
    Signed-off-by: Brice Figureau <brice-puppet at daysofwonder.com>

diff --git a/lib/puppet/util/rdoc/parser.rb b/lib/puppet/util/rdoc/parser.rb
index d7e1c30..61c08b4 100644
--- a/lib/puppet/util/rdoc/parser.rb
+++ b/lib/puppet/util/rdoc/parser.rb
@@ -183,20 +183,24 @@ class Parser
             scan_for_resource(container,stmt.children) if stmt.is_a?(Puppet::Parser::AST::ASTArray)
 
             if stmt.is_a?(Puppet::Parser::AST::Resource) and !stmt.type.nil?
-                type = stmt.type.split("::").collect { |s| s.capitalize }.join("::")
-                title = stmt.title.is_a?(Puppet::Parser::AST::ASTArray) ? stmt.title.to_s.gsub(/\[(.*)\]/,'\1') : stmt.title.to_s
-                Puppet.debug "rdoc: found resource: %s[%s]" % [type,title]
-
-                param = []
-                stmt.params.children.each do |p|
-                    res = {}
-                    res["name"] = p.param
-                    res["value"] = "#{p.value.to_s}" unless p.value.nil?
-
-                    param << res
+                begin
+                    type = stmt.type.split("::").collect { |s| s.capitalize }.join("::")
+                    title = stmt.title.is_a?(Puppet::Parser::AST::ASTArray) ? stmt.title.to_s.gsub(/\[(.*)\]/,'\1') : stmt.title.to_s
+                    Puppet.debug "rdoc: found resource: %s[%s]" % [type,title]
+
+                    param = []
+                    stmt.params.children.each do |p|
+                        res = {}
+                        res["name"] = p.param
+                        res["value"] = "#{p.value.to_s}" unless p.value.nil?
+
+                        param << res
+                    end
+
+                    container.add_resource(PuppetResource.new(type, title, stmt.doc, param))
+                rescue => detail
+                    raise Puppet::ParseError, "impossible to parse resource in #{stmt.file} at line #{stmt.line}: #{detail}"
                 end
-
-                container.add_resource(PuppetResource.new(type, title, stmt.doc, param))
             end
         end
     end
@@ -228,6 +232,8 @@ class Parser
         end
 
         cls.comment = comment
+    rescue => detail
+        raise Puppet::ParseError, "impossible to parse class '#{name}' in #{klass.file} at line #{klass.line}: #{detail}"
     end
 
     # create documentation for a node
@@ -250,6 +256,8 @@ class Parser
         end
 
         n.comment = comment
+    rescue => detail
+        raise Puppet::ParseError, "impossible to parse node '#{name}' in #{node.file} at line #{node.line}: #{detail}"
     end
 
     # create documentation for a define
@@ -287,6 +295,8 @@ class Parser
         meth.visibility = :public
         meth.document_self = true
         meth.singleton = false
+    rescue => detail
+        raise Puppet::ParseError, "impossible to parse definition '#{name}' in #{define.file} at line #{define.line}: #{detail}"
     end
 
     # Traverse the AST tree and produce code-objects node
diff --git a/spec/unit/util/rdoc/parser.rb b/spec/unit/util/rdoc/parser.rb
index de11832..558dac4 100755
--- a/spec/unit/util/rdoc/parser.rb
+++ b/spec/unit/util/rdoc/parser.rb
@@ -213,7 +213,7 @@ describe RDoc::Parser do
 
     describe "when documenting definition" do
         before(:each) do
-            @define = stub_everything 'define', :arguments => [], :doc => "mydoc"
+            @define = stub_everything 'define', :arguments => [], :doc => "mydoc", :file => "file", :line => 42
             @class = stub_everything 'class'
             @parser.stubs(:get_class_or_module).returns([@class, "mydef"])
         end
@@ -228,12 +228,18 @@ describe RDoc::Parser do
 
             @parser.document_define("mydef", @define, @class)
         end
+
+        it "should produce a better error message on unhandled exception" do
+            @class.expects(:add_method).raises(ArgumentError)
+
+            lambda { @parser.document_define("mydef", @define, @class) }.should raise_error(Puppet::ParseError, /in file at line 42/)
+        end
     end
 
     describe "when documenting nodes" do
         before :each do
             @code = stub_everything 'code'
-            @node = stub_everything 'node', :doc => "mydoc", :parentclass => "parent", :code => @code
+            @node = stub_everything 'node', :doc => "mydoc", :parentclass => "parent", :code => @code, :file => "file", :line => 42
             @rdoc_node = stub_everything 'rdocnode'
 
             @class = stub_everything 'class'
@@ -265,12 +271,18 @@ describe RDoc::Parser do
             @parser.expects(:scan_for_resource).with(@rdoc_node, @code)
             @parser.document_node("mynode", @node, @class)
         end
+
+        it "should produce a better error message on unhandled exception" do
+            @class.stubs(:add_node).raises(ArgumentError)
+
+            lambda { @parser.document_node("mynode", @node, @class) }.should raise_error(Puppet::ParseError, /in file at line 42/)
+        end
     end
 
     describe "when documenting classes" do
         before :each do
             @code = stub_everything 'code'
-            @class = stub_everything 'class', :doc => "mydoc", :parentclass => "parent", :code => @code
+            @class = stub_everything 'class', :doc => "mydoc", :parentclass => "parent", :code => @code, :file => "file", :line => 42
             @rdoc_class = stub_everything 'rdoc-class'
 
             @module = stub_everything 'class'
@@ -303,6 +315,12 @@ describe RDoc::Parser do
             @parser.expects(:scan_for_resource).with(@rdoc_class, @code)
             @parser.document_class("mynode", @class, @module)
         end
+
+        it "should produce a better error message on unhandled exception" do
+            @module.stubs(:add_class).raises(ArgumentError)
+
+            lambda { @parser.document_class("mynode", @class, @module) }.should raise_error(Puppet::ParseError, /in file at line 42/)
+        end
     end
 
     describe "when scanning for includes and requires" do

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list