puppetlabs/puppet — pull request #1307 by domcleal (2012-11-30 23:13:42+00:00)
Title: (#17887) Only log if message has been initialized

Inside a test harness with Mocha, it's possible to run the "ensure" block
without having executed either the main or "rescue" blocks if an unexpected
method is executed etc.

If this happens during the property.sync, this causes an immediate exit from
the main block, but the "ensure" block is still run. The event message won't
have been initialized yet, so this then causes the logger to report:

Puppet::Util::Log requires a message

This changes the "ensure" block to only log if it's got as far as writing a
message.

===

I don't know how to write a test for this. I've created the following one which reproduces the problem by making a mocha expectation fire: https://gist.github.com/4179351 (with the fix you'll see an rspec failure, without it you'll see the Puppet::Util::Log message).

But because it causes an rspec failure itself in a "successful" case, this isn't useful to merge. If you have any ideas about how to recreate a similar abrupt exit as mocha does, then that'd be good - else I'd propose merging without a test.