Error handling: Liquid using all memory--solved

12 views
Skip to first unread message

LarryK

unread,
Jun 7, 2009, 4:27:56 PM6/7/09
to Liquid Templates
Hi,

I ran into a problem and have now solved it after some good amount of
work.

My parameters to Liquid render include large models that include many
populated objects. -- I use Liquid for reporting.

Symptoms:
Rendering suddenly stops, and nothing seems to be happening. Watching
the server using top shows the process using up more and more memory
until it fails with a memory allocation error.

Cause:
In Liquid/lib/liquid/context.rb see method handle_error

The problem was that:
1) An error was be raised
2) The handle_error method was calling e.message
BUT, e.message was calling inspect on the arguments. Inspect was
trying to print enormous amounts of data. The system was failing with
a memory allocation error.

Debugging
Added a breakpoint at the entry to handle_error.
-- e is the error arg
in the debugger:
e.class => NoMethodError
e.name => gave the symbol (the method) that could not be found
e.backtrace => showed the backtrace
e.message => wouldn't evaluate (causes memory problem discussed
above).

Possible Liquid change:
Add to the handle_error case statement.
when NoMethodError then "Liquid error: NoMethodError #{e.name.to_s}"

Hope this helps...

Larry
ps. Thanks to Tobias and contributors for terrific software.

Tobias Lütke

unread,
Jun 14, 2009, 12:47:15 PM6/14/09
to liquid-t...@googlegroups.com
This sounds like a good addition. Could you cook up a patch?
Regards
-- tobi
Reply all
Reply to author
Forward
0 new messages