Debug Puppet "Error: Failed to apply catalog: undefined method [...] for nil:NilClass"

If you get e.g. this error message when you try to run puppet agent:

Error: Failed to apply catalog: undefined method `strip' for nil:NilClass

you could have a very bad time debugging it. Because there will be no messages in the logs which could help you.

You should always remember puppet agents --trace option, because that's probably the only way how you can track this error. For example if you have an unparsable mail aliases file you will get this:

# puppet agent --test --trace --noop
Info: Using configured environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Info: Applying configuration version '1558534846'
Error: Failed to apply catalog: undefined method `strip' for nil:NilClass
/usr/local/lib/ruby/site_ruby/2.4/puppet/provider/mailalias/aliases.rb:28:in `process'
/usr/local/lib/ruby/site_ruby/2.4/puppet/util/fileparsing.rb:152:in `handle_record_line'
/usr/local/lib/ruby/site_ruby/2.4/puppet/util/fileparsing.rb:244:in `block in parse_line'
/usr/local/lib/ruby/site_ruby/2.4/puppet/util/fileparsing.rb:240:in `each'
/usr/local/lib/ruby/site_ruby/2.4/puppet/util/fileparsing.rb:240:in `parse_line'
[...]
Kim Klotz Almost 5 years ago