- Optimized RowNum based Oracle limit-dialect (RT#61277)
* Fixes
+ - Make sure exception_action does not allow exception-hiding
+ due to badly-written handlers (the mechanism was never meant
+ to be able to suppress exceptions)
- Fixed rels ending with me breaking subqueried limit realiasing
- Oracle sequence detection now *really* works across schemas
(fixed some ommissions from 0.08123)
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;
=back
-If C<exception_action> is set for this class/object, L</throw_exception>
-will prefer to call this code reference with the exception as an argument,
-rather than L<DBIx::Class::Exception/throw>.
+When L</throw_exception> is invoked and L</exception_action> is set to a code
+reference, this reference will be called instead of
+L<DBIx::Class::Exception/throw>, 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<exception_action> to suppress a particular exception
-completely, simply have it return true.
+Your custom throw code B<must> rethrow the exception, as L</throw_exception> is
+an integral part of DBIC's internal execution control flow.
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
=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
use warnings;
use Test::More;
+use Test::Exception;
+use Test::Warn;
use lib qw(t/lib);
use DBICTest;
my $ex_regex = qr/Odd number of arguments to search/;
# Basic check, normal exception
-eval { throwex };
-my $e = $@; # like() seems to stringify $@
-like($@, $ex_regex);
+throws_ok { throwex }
+ $ex_regex;
+
+my $e = $@;
# Re-throw the exception with rethrow()
-eval { $e->rethrow };
+throws_ok { $e->rethrow }
+ $ex_regex;
isa_ok( $@, 'DBIx::Class::Exception' );
-like($@, $ex_regex);
# Now lets rethrow via exception_action
$schema->exception_action(sub { die @_ });
-eval { throwex };
-like($@, $ex_regex);
+throws_ok { throwex }
+ $ex_regex;
+#
+# This should have never worked!!!
+#
# Now lets suppress the error
$schema->exception_action(sub { 1 });
-eval { throwex };
-ok(!$@, "Suppress exception");
+throws_ok { throwex }
+ qr/exception_action handler .+ did \*not\* result in an exception.+original error: $ex_regex/;
# Now lets fall through and let croak take back over
$schema->exception_action(sub { return });
-eval { throwex };
-like($@, $ex_regex);
+throws_ok {
+ warnings_are { throwex }
+ qr/exception_action handler installed .+ returned false instead throwing an exception/;
+} $ex_regex;
+
+# again to see if no warning
+throws_ok {
+ warnings_are { throwex }
+ [];
+} $ex_regex;
+
# Whacky useless exception class
{
# Try the exception class
$schema->exception_action(sub { DBICTest::Exception->throw(@_) });
-eval { throwex };
-like($@, qr/DBICTest::Exception is handling this: $ex_regex/);
+throws_ok { throwex }
+ qr/DBICTest::Exception is handling this: $ex_regex/;
# While we're at it, lets throw a custom exception through Storage::DBI
-eval { $schema->storage->throw_exception('floob') };
-like($@, qr/DBICTest::Exception is handling this: floob/);
-
+throws_ok { $schema->storage->throw_exception('floob') }
+ qr/DBICTest::Exception is handling this: floob/;
done_testing;