Skip to content

Commit

Permalink
improved Mojo::Exception context detection to better line up with use…
Browse files Browse the repository at this point in the history
…r expectations
  • Loading branch information
kraih committed Feb 22, 2014
1 parent e950d36 commit 012773c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Changes
Expand Up @@ -2,6 +2,8 @@
4.84 2014-02-22
- Added remaining attribute to Mojo::IOLoop::Delay.
- Added data and pass methods to Mojo::IOLoop::Delay.
- Improved Mojo::Exception context detection to better line up with user
expectations.

4.83 2014-02-19
- Improved Mojo::JSON to handle encoding errors more gracefully.
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojo/Exception.pm
Expand Up @@ -84,7 +84,7 @@ sub _detect {

# Extract file and line from stacktrace
my $first = $self->frames->[0];
unshift @trace, [$first->[1], $first->[2]] if $first;
push @trace, [$first->[1], $first->[2]] if $first;

# Search for context in files
for my $frame (@trace) {
Expand All @@ -94,7 +94,7 @@ sub _detect {
}

# More context
$self->_context($trace[0][1], [map { [split "\n"] } @$files]) if $files;
$self->_context($trace[-1][1], [map { [split "\n"] } @$files]) if $files;

return $self;
}
Expand Down
7 changes: 7 additions & 0 deletions t/mojolicious/exception_lite_app.t
Expand Up @@ -71,6 +71,8 @@ get '/missing_template/too' => sub {
or $self->res->headers->header('X-Not-Found' => 1);
};

get '/missing_helper' => sub { shift->missing_helper };

# Dummy exception object
package MyException;
use Mojo::Base -base;
Expand Down Expand Up @@ -223,6 +225,11 @@ $t->get_ok('/missing_template/too')->status_is(404)
->header_is('X-Not-Found' => 1)->content_type_is('text/html;charset=UTF-8')
->content_like(qr/Page not found/);

# Missing helper (correct context)
$t->get_ok('/missing_helper')->status_is(500)
->content_type_is('text/html;charset=UTF-8')->content_like(qr/Server error/)
->content_like(qr/shift->missing_helper/);

# Reuse exception
ok !$exception, 'no exception';
ok !$snapshot, 'no snapshot';
Expand Down

0 comments on commit 012773c

Please sign in to comment.