From 989ea57cf907bbc852d028658c261829a78a3825 Mon Sep 17 00:00:00 2001 From: Matthias Bethke Date: Thu, 17 May 2012 14:00:17 -0600 Subject: [PATCH] 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';