The Puppet Labs Issue Tracker has Moved: https://tickets.puppetlabs.com

This issue tracker is now in read-only archive mode and automatic ticket export has been disabled. Redmine users will need to create a new JIRA account to file tickets using https://tickets.puppetlabs.com. See the following page for information on filing tickets with JIRA:

Bug #5220

when namevar is not specified for a type, error message is 'undefined method `merge' for []:Array'

Added by Dan Bode over 5 years ago. Updated over 3 years ago.

Status:AcceptedStart date:11/08/2010
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:RAL
Target version:-
Affected Puppet version: Branch:
Keywords:

We've Moved!

Ticket tracking is now hosted in JIRA: https://tickets.puppetlabs.com


Description

a more useful message would be helpful.

stack trace:

 root@puppet:/etc/puppet/modules# puppet apply --trace --debug tests/openfire.pp 
/usr/lib/ruby/1.8/puppet/resource.rb:206:in `to_hash'
/usr/lib/ruby/1.8/puppet/type.rb:1730:in `initialize'
/usr/lib/ruby/1.8/puppet/resource.rb:246:in `new'
/usr/lib/ruby/1.8/puppet/resource.rb:246:in `to_ral'
/usr/lib/ruby/1.8/puppet/resource/catalog.rb:553:in `send'
/usr/lib/ruby/1.8/puppet/resource/catalog.rb:553:in `to_catalog'
/usr/lib/ruby/1.8/puppet/resource/catalog.rb:531:in `each'
/usr/lib/ruby/1.8/puppet/resource/catalog.rb:531:in `to_catalog'
/usr/lib/ruby/1.8/puppet/resource/catalog.rb:468:in `to_ral'
/usr/lib/ruby/1.8/puppet/application/apply.rb:118:in `main'
/usr/lib/ruby/1.8/puppet/application/apply.rb:35:in `run_command'
/usr/lib/ruby/1.8/puppet/application.rb:300:in `run'
/usr/lib/ruby/1.8/puppet/application.rb:397:in `exit_on_fail'
/usr/lib/ruby/1.8/puppet/application.rb:300:in `run'
/usr/lib/ruby/1.8/puppet/util/command_line.rb:55:in `execute'
/usr/bin/puppet:4
undefined method `merge' for []:Array

Related issues

Related to Puppet - Bug #15264: Custom title patterns can fail cryptically Closed 06/27/2012
Duplicated by Puppet - Bug #15046: bad error message for type defined without namevar Needs Decision 06/14/2012

History

#1 Updated by Markus Roberts over 5 years ago

  • Status changed from Unreviewed to Investigating
  • Affected Puppet version changed from 2.6.3rc2 to 2.6.3rc1

I note that this wasn’t on 2.6.3rc3; by the stack trace it would have had to be 2.6.3rc1 or earlier.

#2 Updated by Markus Roberts over 5 years ago

  • Assignee set to Markus Roberts

#3 Updated by Dan Bode over 5 years ago

/usr/lib/ruby/site_ruby/1.8/puppet/resource.rb:206:in `to_hash'
/usr/lib/ruby/site_ruby/1.8/puppet/type.rb:1730:in `initialize'
/usr/lib/ruby/site_ruby/1.8/puppet/resource.rb:246:in `new'
/usr/lib/ruby/site_ruby/1.8/puppet/resource.rb:246:in `to_ral'
/usr/lib/ruby/site_ruby/1.8/puppet/resource/catalog.rb:553:in `send'
/usr/lib/ruby/site_ruby/1.8/puppet/resource/catalog.rb:553:in `to_catalog'
/usr/lib/ruby/site_ruby/1.8/puppet/resource/catalog.rb:531:in `each'
/usr/lib/ruby/site_ruby/1.8/puppet/resource/catalog.rb:531:in `to_catalog'
/usr/lib/ruby/site_ruby/1.8/puppet/resource/catalog.rb:468:in `to_ral'
/usr/lib/ruby/site_ruby/1.8/puppet/application/apply.rb:118:in `main'
/usr/lib/ruby/site_ruby/1.8/puppet/application/apply.rb:35:in `run_command'
/usr/lib/ruby/site_ruby/1.8/puppet/application.rb:287:in `run'
/usr/lib/ruby/site_ruby/1.8/puppet/application.rb:393:in `exit_on_fail'
/usr/lib/ruby/site_ruby/1.8/puppet/application.rb:287:in `run'
/usr/lib/ruby/site_ruby/1.8/puppet/util/command_line.rb:55:in `execute'
/usr/bin/puppet:4
undefined method `merge' for []:Array

#4 Updated by Dan Bode over 5 years ago

the last comment updates the stacktrace for 2.6.3rc2

#5 Updated by Anonymous over 4 years ago

  • Assignee changed from Markus Roberts to Dan Bode
  • Affected Puppet version deleted (2.6.3rc1)

Dan, is this still an issue?

#6 Updated by Dan Bode over 4 years ago

yes it is. I actually run into this regularly when I teach the developers class

#7 Updated by Matt Robinson over 4 years ago

  • Assignee changed from Dan Bode to Matt Robinson

I just ran into this while testing too and would like to resolve it because it’s a pain to track down, but am not sure of the correct behavior.

You can also get around this error by declaring a name parameter for your type.

Puppet.newtype('blond') do
  newparam(:name)
end

Should types be required to declare a namevar or at least the parameter name? If so, then we should probably raise an error when the type is declared. This seems likely to me. My understanding of namevar is that it’s like a primary key for resources, so we should almost certainly have one.

If not then, something probably needs to be fixed in the area of lib/puppet/resource.rb in the parse_title method or in lib/puppet/type.rb title_patterns method so that a hash is returned instead of an array.

#8 Updated by Anonymous over 4 years ago

Matt Robinson wrote:

I just ran into this while testing too and would like to resolve it because it’s a pain to track down, but am not sure of the correct behavior.

Should types be required to declare a namevar or at least the parameter name? If so, then we should probably raise an error when the type is declared. This seems likely to me. My understanding of namevar is that it’s like a primary key for resources, so we should almost certainly have one.

They need some sort of name, yeah, so I think this is the right thing to do: enforce that. IIRC, the code will implicitly fill in the namevar from the title, but that you need to declare which one is namevar, so this should be easy enough: when finished loading the type, check that constraint, and if not satisfied, hard-fail.

…or maybe soft-fail and just pull the type back out. I like the hard fail, but maybe we prefer not to break an entire infrastructure because you sync out a broken type from some random module…

If not then, something probably needs to be fixed in the area of lib/puppet/resource.rb in the parse_title method or in lib/puppet/type.rb title_patterns method so that a hash is returned instead of an array.

Feels like papering over the problem, and I would want to see some pretty convincing arguments why we should (continue to) allow that, if it turned out we didn’t enforce having a namevar.

#9 Updated by Anonymous about 4 years ago

Just ran into this myself. I think we should make it clear the namevar needs to be a parameter and not a property. that’s what threw me for awhile on this.

Thanks for logging the stacktrace Dan. Google led me straight here.

#10 Updated by Anonymous about 4 years ago

  • Assignee deleted (Matt Robinson)

#11 Updated by Anonymous over 3 years ago

  • Status changed from Investigating to Accepted

The behavior around this has been changed by the fix for #15264. The error message generated is still not that helpful to diagnose the actual error in this case, but at least it doesn’t complain about a method call on Array.

The issue can easily be reproduced by creating a type that is:

> cat ~/.puppet/modules/testing/lib/puppet/type/testing.rb
Puppet.newtype(:testing) do
end

And then the issue shows up as:

> puppet apply -e "testing { h: }"
Error: No set of title patterns matched the title "h".

Which before the fix to #15264 was:

> puppet apply -e "testing { h: }"
Error: undefined method `merge' for []:Array

I’m moving this back into accepted since it has no current activity on it.

Also available in: Atom PDF