Issue #15046 has been updated by eric sorenson.

Status changed from Unreviewed to Investigating
Assignee set to Chris Price

Chris, does the error messages guidance from UX help you craft an error? Seems 
like since you went through all the work to track this down it'd be a shame not 
to fix it.
----------------------------------------
Bug #15046: bad error message for type defined without namevar
https://projects.puppetlabs.com/issues/15046#change-68891

Author: Chris Price
Status: Investigating
Priority: Low
Assignee: Chris Price
Category: 
Target version: 
Affected Puppet version: 
Keywords: 
Branch: 


If you write a type that looks like this:

<pre>
Puppet::Type.newtype(:foo) do

  ensurable do
    defaultvalues
    defaultto :present
  end
end
</pre>

And you then try to instantiate it using something like:

<pre>
resource = Puppet::Type::Foo.new(:title => 'myfoo')
</pre>

You will get a very bad error message about Array not having a method called 
"merge" or something to that effect.  This is because in lib/puppet/type.rb 
around line 225 we have:

<pre> 
def self.title_patterns
    case key_attributes.length
    when 0; []
    when 1;
...
</pre>

Which returns an empty array if there is no namevar, and then in 
lib/puppet/resource.rb around line 423:

<pre>
def parse_title
    h = {}
    type = resource_type
    <b>if type.respond_to? :title_patterns</b>
      type.title_patterns.each { |regexp, symbols_and_lambdas|
        if captures = regexp.match(title.to_s)
          symbols_and_lambdas.zip(captures[1..-1]).each { 
|symbol_and_lambda,capture|
            sym, lam = symbol_and_lambda
            #self[sym] = lam.call(capture)
            h[sym] = lam.call(capture)
          }
          <b>return h</b>
        end
      }
    <b>else</b>
      return { :name => title.to_s }
    end
  end
</pre>

Basically this method falls through and unintentionally returns that empty 
array in that case... which leads to a very bad error message.  I would have 
submitted a fix but I'm not sure what the desired behavior is; I suspect it's 
that we should give a clear error message about there being no namevar, but if 
so, I'm not sure whether that should happen in type.rb or resource.rb.


-- 
You have received this notification because you have either subscribed to it, 
or are involved in it.
To change your notification preferences, please click here: 
http://projects.puppetlabs.com/my/account

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Bugs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-bugs?hl=en.

Reply via email to