SERVER-556 was filed against Puppet Server. After some investigation, it seems that when an error is thrown in Puppet's template function, Ruby will call inspect on the top-level scope object, but not use the returned string.
However, since the Puppet::Parser::Scope class has no inspect method of its own, inspecting the scope object causes an absolutely massive string to be produced and never used. The more code the user has in their environment, the larger the string. This string can grow so large that it can cause an OOM error when running Puppet Server due to the restrictions placed on the heap size.
We need to add an inspect method to the Puppet::Parser::Scope class that returns something simple to avoid this.