Skip to content

Commit

Permalink
all Mojo::Template exceptions need to be verbose
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Feb 26, 2016
1 parent ae4609a commit f43f5fd
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -6,6 +6,7 @@
- Improved val method in Mojo::DOM with support for "on" default values.
- Fixed url_for bug where routes with custom names would not match in the same
order as routes with automatically generated names.
- Fixed bug in Mojo::Template where not all exceptions were verbose.
- Fixed Windows bug in "util.t".

6.48 2016-02-24
Expand Down
3 changes: 1 addition & 2 deletions lib/Mojo/Exception.pm
Expand Up @@ -32,7 +32,7 @@ sub inspect {

sub new { @_ > 1 ? shift->SUPER::new(message => shift) : shift->SUPER::new }

sub throw { die shift->new(shift)->trace(2)->inspect(@_) }
sub throw { die shift->new(shift)->trace(2)->inspect }

sub to_string {
my $self = shift;
Expand Down Expand Up @@ -185,7 +185,6 @@ Construct a new L<Mojo::Exception> object and assign L</"message"> if necessary.
=head2 throw
Mojo::Exception->throw('Something went wrong!');
Mojo::Exception->throw('Something went wrong!', $source1, $source2);
Throw exception from the current execution context.
Expand Down
3 changes: 2 additions & 1 deletion lib/Mojo/Template.pm
Expand Up @@ -102,7 +102,8 @@ sub interpret {
# Stack trace
local $SIG{__DIE__} = sub {
CORE::die($_[0]) if ref $_[0];
Mojo::Exception->throw(shift, $self->unparsed, $self->code);
die Mojo::Exception->new(shift)
->trace->inspect($self->unparsed, $self->code)->verbose(1);
};

return undef unless my $compiled = $self->compiled;
Expand Down
9 changes: 9 additions & 0 deletions t/mojo/template.t
Expand Up @@ -605,6 +605,7 @@ test
EOF
isa_ok $output, 'Mojo::Exception', 'right exception';
is $output->message, "x\n", 'right message';
ok $output->verbose, 'verbose exception';
is $output->lines_before->[0][0], 1, 'right number';
is $output->lines_before->[0][1], 'test', 'right line';
is $output->lines_before->[1][0], 2, 'right number';
Expand All @@ -626,6 +627,7 @@ test
EOF
isa_ok $output, 'Mojo::Exception', 'right exception';
like $output->message, qr/Missing right curly/, 'right message';
ok $output->verbose, 'verbose exception';
is $output->lines_before->[0][0], 1, 'right number';
is $output->lines_before->[0][1], 'test', 'right line';
is $output->lines_before->[1][0], 2, 'right number';
Expand All @@ -650,6 +652,7 @@ test
EOF
isa_ok $output, 'Mojo::Exception', 'right exception';
like $output->message, qr/ohoh/, 'right message';
ok $output->verbose, 'verbose exception';
is $output->lines_before->[0][0], 15, 'right number';
is $output->lines_before->[0][1], '}', 'right line';
is $output->lines_before->[1][0], 16, 'right number';
Expand Down Expand Up @@ -681,6 +684,7 @@ test
EOF
isa_ok $output, 'Mojo::Exception', 'right exception';
like $output->message, qr/oops!/, 'right message';
ok $output->verbose, 'verbose exception';
is $output->lines_before->[0][0], 1, 'right number';
is $output->lines_before->[0][1], 'test', 'right line';
is $output->lines_before->[1][0], 2, 'right number';
Expand Down Expand Up @@ -712,6 +716,7 @@ test
EOF
isa_ok $output, 'Mojo::Exception', 'right exception';
like $output->message, qr/oops!/, 'right message';
ok $output->verbose, 'verbose exception';
is $output->lines_before->[0][0], 1, 'right number';
is $output->lines_before->[0][1], 'test\\\\', 'right line';
ok $output->lines_before->[0][2], 'contains code';
Expand Down Expand Up @@ -1092,6 +1097,7 @@ $file = catfile dirname(__FILE__), 'templates', 'exception.mt';
$output = $mt->render_file($file);
isa_ok $output, 'Mojo::Exception', 'right exception';
like $output->message, qr/exception\.mt line 2/, 'message contains filename';
ok $output->verbose, 'verbose exception';
is $output->lines_before->[0][0], 1, 'right number';
is $output->lines_before->[0][1], 'test', 'right line';
is $output->line->[0], 2, 'right number';
Expand All @@ -1106,6 +1112,7 @@ $output = $mt->name('"foo.mt" from DATA section')->render_file($file);
isa_ok $output, 'Mojo::Exception', 'right exception';
like $output->message, qr/foo\.mt from DATA section line 2/,
'message contains filename';
ok $output->verbose, 'verbose exception';
is $output->lines_before->[0][0], 1, 'right number';
is $output->lines_before->[0][1], 'test', 'right line';
is $output->line->[0], 2, 'right number';
Expand All @@ -1119,6 +1126,7 @@ $mt = Mojo::Template->new;
$file = catfile dirname(__FILE__), 'templates', 'utf8_exception.mt';
$output = $mt->render_file($file);
isa_ok $output, 'Mojo::Exception', 'right exception';
ok $output->verbose, 'verbose exception';
is $output->lines_before->[0][1], '', 'right line';
is $output->line->[1], '% die;♥', 'right line';
is $output->lines_after->[0][1], '', 'right line';
Expand All @@ -1128,6 +1136,7 @@ $mt = Mojo::Template->new;
$output = $mt->render('<% die "Test at template line 99\n"; %>');
isa_ok $output, 'Mojo::Exception', 'right exception';
is $output->message, "Test at template line 99\n", 'right message';
ok $output->verbose, 'verbose exception';
is $output->lines_before->[0], undef, 'no lines before';
is $output->line->[0], 1, 'right number';
is $output->line->[1], '<% die "Test at template line 99\n"; %>', 'right line';
Expand Down

0 comments on commit f43f5fd

Please sign in to comment.