From 4fec29f28811a519f3c2f3d9ca4f8427ef071eae Mon Sep 17 00:00:00 2001 From: Austin Mills Date: Mon, 10 Jan 2011 14:55:05 -0600 Subject: [PATCH] OPS-250 Modifying liquid error handling so that it no longer captures Exceptions that are not subclasses of StandardError (previously, it was rescuing things like Interrupt and NoMemoryError). --- lib/liquid/block.rb | 2 +- test/lib/liquid/error_handling_test.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/liquid/block.rb b/lib/liquid/block.rb index 10df350..b16de4c 100644 --- a/lib/liquid/block.rb +++ b/lib/liquid/block.rb @@ -92,7 +92,7 @@ module Liquid list.collect do |token| begin token.respond_to?(:render) ? token.render(context) : token - rescue Exception => e + rescue ::StandardError => e context.handle_error(e) end end diff --git a/test/lib/liquid/error_handling_test.rb b/test/lib/liquid/error_handling_test.rb index e561e3d..22603bb 100644 --- a/test/lib/liquid/error_handling_test.rb +++ b/test/lib/liquid/error_handling_test.rb @@ -13,6 +13,10 @@ class ErrorDrop < Liquid::Drop raise Liquid::SyntaxError, 'syntax error' end + def exception + raise Exception, 'exception' + end + end class ErrorHandlingTest < Test::Unit::TestCase @@ -66,4 +70,12 @@ class ErrorHandlingTest < Test::Unit::TestCase assert_equal Liquid::ArgumentError, template.errors.first.class end end + + # Liquid should not catch Exceptions that are not subclasses of StandardError, like Interrupt and NoMemoryError + def test_exceptions_propagate + assert_raise Exception do + template = Liquid::Template.parse( ' {{ errors.exception }} ' ) + template.render('errors' => ErrorDrop.new) + end + end end # ErrorHandlingTest