X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FSchema.pm;h=77a7fe7e511d1eba2d9e71b20309f1949c7879b1;hb=ddabf34f6bef467bc213d2263f5ab2eb4d463b24;hp=8046903acf4fd1d8bcbee6f05539c307bbbd7378;hpb=6298a324307439b76419d0f5db453b0d10f10517;p=dbsrgits%2FDBIx-Class-Historic.git diff --git a/lib/DBIx/Class/Schema.pm b/lib/DBIx/Class/Schema.pm index 8046903..77a7fe7 100644 --- a/lib/DBIx/Class/Schema.pm +++ b/lib/DBIx/Class/Schema.pm @@ -4,7 +4,7 @@ use strict; use warnings; use DBIx::Class::Exception; -use Carp::Clan qw/^DBIx::Class/; +use Carp::Clan qw/^DBIx::Class|^Try::Tiny/; use Try::Tiny; use Scalar::Util 'weaken'; use File::Spec; @@ -438,14 +438,13 @@ L for an example of this. =back -If C is set for this class/object, L -will prefer to call this code reference with the exception as an argument, -rather than L. +When L is invoked and L is set to a code +reference, this reference will be called instead of +L, with the exception message passed as the only +argument. -Your subroutine should probably just wrap the error in the exception -object/class of your choosing and rethrow. If, against all sage advice, -you'd like your C to suppress a particular exception -completely, simply have it return true. +Your custom throw code B rethrow the exception, as L is +an integral part of DBIC's internal execution control flow. Example: @@ -459,9 +458,6 @@ Example: my $schema_obj = My::Schema->connect( .... ); $schema_obj->exception_action(sub { My::ExceptionClass->throw(@_) }); - # suppress all exceptions, like a moron: - $schema_obj->exception_action(sub { 1 }); - =head2 stacktrace =over 4 @@ -1031,11 +1027,29 @@ default behavior will provide a detailed stack trace. =cut +my $false_exception_action_warned; sub throw_exception { my $self = shift; - DBIx::Class::Exception->throw($_[0], $self->stacktrace) - if !$self->exception_action || !$self->exception_action->(@_); + if (my $act = $self->exception_action) { + if ($act->(@_)) { + DBIx::Class::Exception->throw( + "Invocation of the exception_action handler installed on $self did *not*" + .' result in an exception. DBIx::Class is unable to function without a reliable' + .' exception mechanism, ensure that exception_action does not hide exceptions' + ." (original error: $_[0])" + ); + } + elsif(! $false_exception_action_warned++) { + carp ( + "The exception_action handler installed on $self returned false instead" + .' of throwing an exception. This behavior has been deprecated, adjust your' + .' handler to always rethrow the supplied error.' + ); + } + } + + DBIx::Class::Exception->throw($_[0], $self->stacktrace); } =head2 deploy