From 989ea57cf907bbc852d028658c261829a78a3825 Mon Sep 17 00:00:00 2001 From: Matthias Bethke Date: Thu, 17 May 2012 14:00:17 -0600 Subject: [PATCH 1/4] Fixed double TT rendering on error If a template produced a rendering error in process() but did not produce one when called without stash variables, the Mojo::Exception would be built incorrectly, leading to an exception that masked the original error. --- lib/Mojolicious/Plugin/TtRenderer/Engine.pm | 4 +--- t/tt_plugin_lite_app.t | 9 +++++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/Mojolicious/Plugin/TtRenderer/Engine.pm b/lib/Mojolicious/Plugin/TtRenderer/Engine.pm index cb85120..3a87e3f 100644 --- a/lib/Mojolicious/Plugin/TtRenderer/Engine.pm +++ b/lib/Mojolicious/Plugin/TtRenderer/Engine.pm @@ -85,9 +85,7 @@ sub _render { # Error unless ($ok) { - my $e = Mojo::Exception->new( - $self->tt->error.'', - $self->tt->service->process(defined $inline ? \$inline : $t)); + my $e = Mojo::Exception->new($self->tt->error.''); $$output = ''; $c->app->log->error(qq/Template error in "$t": $e/); $c->render_exception($e); diff --git a/t/tt_plugin_lite_app.t b/t/tt_plugin_lite_app.t index 94ae154..0a0859c 100644 --- a/t/tt_plugin_lite_app.t +++ b/t/tt_plugin_lite_app.t @@ -15,7 +15,7 @@ BEGIN { $ENV{MOJO_TMPDIR} ||= File::Temp::tempdir } # Make sure sockets are working plan skip_all => 'working sockets required for this test!' unless Mojo::IOLoop->new->generate_port; -plan tests => 3; +plan tests => 5; # Leela: OK, this has gotta stop. I'm going to remind Fry of his humanity the way only a woman can. # Farnsworth: You're going to do his laundry? @@ -30,13 +30,18 @@ plugin 'tt_renderer'; app->log->level('error'); # GET / -get '/' => 'index'; +get '/' => 'index'; +get '/blow' => sub { + shift->render(template => 'conditional-exception', do_process => 1); +}; + my $t = Test::Mojo->new; # Simple TT template $t->get_ok('/')->status_is(200) ->content_like(qr/test123456/); +$t->get_ok('/blow')->content_like(qr/file error - doesnotexist.tt: No such file or directory/); eval " use Devel::Cycle 'find_cycle'; From 92bb64406bf0600959e2dcab8364c7f923c43287 Mon Sep 17 00:00:00 2001 From: Matthias Bethke Date: Fri, 18 May 2012 00:37:18 -0600 Subject: [PATCH 2/4] Checking HTTP status code in TT render error test --- t/tt_plugin_lite_app.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/tt_plugin_lite_app.t b/t/tt_plugin_lite_app.t index 0a0859c..533b5f8 100644 --- a/t/tt_plugin_lite_app.t +++ b/t/tt_plugin_lite_app.t @@ -41,7 +41,7 @@ my $t = Test::Mojo->new; # Simple TT template $t->get_ok('/')->status_is(200) ->content_like(qr/test123456/); -$t->get_ok('/blow')->content_like(qr/file error - doesnotexist.tt: No such file or directory/); +$t->get_ok('/blow')->status_is(500)->content_like(qr/file error - doesnotexist.tt: No such file or directory/); eval " use Devel::Cycle 'find_cycle'; From bbfab8db4ee4db6557d860bcbc7f6aac7e3c5355 Mon Sep 17 00:00:00 2001 From: Matthias Bethke Date: Fri, 18 May 2012 00:40:50 -0600 Subject: [PATCH 3/4] Checking HTTP status code for TT render error test --- t/tt_plugin_lite_app.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/tt_plugin_lite_app.t b/t/tt_plugin_lite_app.t index 533b5f8..575b588 100644 --- a/t/tt_plugin_lite_app.t +++ b/t/tt_plugin_lite_app.t @@ -15,7 +15,7 @@ BEGIN { $ENV{MOJO_TMPDIR} ||= File::Temp::tempdir } # Make sure sockets are working plan skip_all => 'working sockets required for this test!' unless Mojo::IOLoop->new->generate_port; -plan tests => 5; +plan tests => 6; # Leela: OK, this has gotta stop. I'm going to remind Fry of his humanity the way only a woman can. # Farnsworth: You're going to do his laundry? From 96d31d45a067a8525739353e7b8ead0cb1edc934 Mon Sep 17 00:00:00 2001 From: Matthias Bethke Date: Fri, 18 May 2012 00:41:21 -0600 Subject: [PATCH 4/4] Added template for render error test --- t/templates/conditional-exception.html.tt | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 t/templates/conditional-exception.html.tt diff --git a/t/templates/conditional-exception.html.tt b/t/templates/conditional-exception.html.tt new file mode 100644 index 0000000..8a6ba36 --- /dev/null +++ b/t/templates/conditional-exception.html.tt @@ -0,0 +1,4 @@ +foo +[% PROCESS doesnotexist.tt IF do_process %] +bar +