puppetlabs/puppet — pull request #677 by jeffmccune (2012-04-17 18:49:51+00:00)
Title: (#13070) Fix undefined method 'downcase' for nil:NilClass Error

Without this patch `puppet describe --list` blows up with the
mount_providers module with the following error:

root@ubuntu-10:/etc/puppetlabs/puppet/modules# puppet describe mounttab
Could not run: Could not autoload /etc/puppetlabs/puppet/modules/puppetlabs-mount-providers/lib/puppet/type/mountpoint.rb:undefined method 'downcase' for nil:NilClass

The root cause of this problem is Puppet evaluating a block of code that
assumes the name of the class it is evaluated in is named something
like `Puppet::Type::Ssh_authorized_key::ParameterProvider`

This assumption is wrong, in the case of the mount_providers module the
class generated by genthing() is named simply "Class" without any
delimiters. This causes the split('::')[2] to return a nil object which
cannot respond to the downcase method.

This patch solves the problem in two ways. First and foremost, the
scope the block of code is evaluated in is unpredictable without this
patch. This patch moves the block of code into a place where the
assumption being made is in fact correct. By moving the description
assignment outside of the block class_eval()'d by genthing() and into
the scope of the Type#providify() we're matching up assumptions and
providing a consistent context to work with.

The second solution is to be much more defensive about calling methods
on split strings. We simply check if we got something back from the
split, and if so call downcase on it. If we don't get something back we
simply call self.to_s which should always return some string and not a
nil object.

The spec tests are not changed because the original commit 27057a69
contains the necessary test coverage.