From 87c5c30fe8d2bbc31dabeb7383f5e5703a732bc5 Mon Sep 17 00:00:00 2001 From: Dan Bode Date: Tue, 11 Jan 2011 20:00:32 -0600 Subject: (#5910) Improved logging when declared classes cannot be found: Previously, when a class could not be found, it was displaying the same error message as when a resource type could not be found. This resulted in confusing error message: Invalid resource type class, when really it should display the name of the class that could not be found. My patch changes the error message to: Could not find declared class #{title} --- lib/puppet/resource.rb | 9 +++++++-- spec/unit/resource_spec.rb | 8 ++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/puppet/resource.rb b/lib/puppet/resource.rb index 4f0d50750..6821e0e06 100644 --- a/lib/puppet/resource.rb +++ b/lib/puppet/resource.rb @@ -201,8 +201,13 @@ class Puppet::Resource tag(self.title) if valid_tag?(self.title) @reference = Reference.new(@type,@title) # for serialization compatibility with 0.25.x - - raise ArgumentError, "Invalid resource type #{type}" if strict? and ! resource_type + if strict? and ! resource_type + if @type == 'Class' + raise ArgumentError, "Could not find declared class #{title}" + else + raise ArgumentError, "Invalid resource type #{type}" + end + end end def ref diff --git a/spec/unit/resource_spec.rb b/spec/unit/resource_spec.rb index e65e8a13a..11ff904bb 100755 --- a/spec/unit/resource_spec.rb +++ b/spec/unit/resource_spec.rb @@ -98,6 +98,14 @@ describe Puppet::Resource do lambda { Puppet::Resource.new("foo") }.should raise_error(ArgumentError) end + it 'should fail if strict is set and type does not exist' do + lambda { Puppet::Resource.new('foo', 'title', {:strict=>true}) }.should raise_error(ArgumentError, 'Invalid resource type foo') + end + + it 'should fail if strict is set and class does not exist' do + lambda { Puppet::Resource.new('Class', 'foo', {:strict=>true}) }.should raise_error(ArgumentError, 'Could not find declared class foo') + end + it "should fail if the title is a hash and the type is not a valid resource reference string" do lambda { Puppet::Resource.new({:type => "foo", :title => "bar"}) }.should raise_error(ArgumentError, 'Puppet::Resource.new does not take a hash as the first argument. Did you mean ("foo", "bar") ?' -- cgit