Permalink
Browse files

Merge branch 'exceptions_and_hooks' into devel

  • Loading branch information...
2 parents ea5f6d8 + b820c03 commit 245734e67fbfb011d5900c2dd903817b728798b6 @dams dams committed Feb 29, 2012
Showing with 47 additions and 14 deletions.
  1. +7 −0 CHANGES
  2. +2 −14 lib/Dancer/Hook.pm
  3. +38 −0 t/25_exceptions/03_exceptions.t
View
@@ -1,5 +1,12 @@
{{$NEXT}}
+ [ BUG FIXES ]
+ * GH #752: Exceptions raised in hooks were not propagated back to the route
+ code, but instead canceleld and replaced by a Dancer halt exception. That
+ was wrong. Now it is fixed, exceptions raised in hooks can be properly
+ caught in route code.
+ (Damien Krotkine)
+
1.3093 29.02.2012
[ BUG FIXES ]
View
@@ -57,20 +57,8 @@ sub new {
Dancer::Logger::core( "entering " . $hook_name . " hook" );
-
- try { $code->(@arguments) }
- catch {
- my ($exception) = @_;
- # exception is not a workflow continuation but a genuine error
- my $err = Dancer::Error->new(
- code => 500,
- title => $hook_name . ' filter error',
- message => "An error occured while executing the filter named $hook_name: $exception",
- exception => $exception,
- );
- # raise a new halt exception
- Dancer::halt( $err->render );
- };
+ $code->(@arguments);
+
};
$self->properties($properties);
@@ -0,0 +1,38 @@
+use strict;
+use warnings;
+use Test::More import => ['!pass'];
+
+use Dancer ':syntax';
+use Dancer::Test;
+
+BEGIN { use_ok('Dancer::Exception', ':all'); }
+
+set views => path( 't', '25_exceptions', 'views' );
+
+{
+ # raise in hook but catch it from route
+ my $flag = 0;
+ my $properly_caught_error = 0;
+ hook before_template_render => sub {
+ $flag++
+ or raise Generic => 'foo5';
+ };
+ get '/raise_in_hook' => sub {
+ try {
+ # should raise
+ template 'index', { foo => 'baz5' };
+ } catch {
+ $properly_caught_error = 1;
+ # won't raise, flag is > 0
+ template 'index', { foo => 'baz5' };
+ }
+ };
+ route_exists [ GET => '/raise_in_hook' ];
+ $flag = 0;
+ response_status_is( [ GET => '/raise_in_hook' ], 200 => "route didn't error");
+ is $properly_caught_error, 1, 'properly caught exception';
+ $flag = 0;
+ response_content_like( [ GET => '/raise_in_hook' ], qr|foo => baz5| );
+}
+
+done_testing();

0 comments on commit 245734e

Please sign in to comment.