From: Arthur Axel 'fREW' Schmidt Date: Wed, 1 Sep 2010 17:42:58 +0000 (-0500) Subject: Preserve unblessed reference exceptions X-Git-Tag: v0.08124~88 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FDBIx-Class.git;a=commitdiff_plain;h=c6d30d5e0e80fb465dc71e0f20de176f35b4261f Preserve unblessed reference exceptions --- diff --git a/Changes b/Changes index be94692..d374507 100644 --- a/Changes +++ b/Changes @@ -30,6 +30,8 @@ Revision history for DBIx::Class so that test relying on the order of %{} will no longer fail - Fixed mysterious ::Storage::DBI goto-shim failures on older perl versions + - Non-blessed reference exceptions are now correctly preserved + when thrown from udner DBIC (e.g. from txn_do) * Misc - Refactored capability handling in Storage::DBI, allows for diff --git a/lib/DBIx/Class/Exception.pm b/lib/DBIx/Class/Exception.pm index 46a85f6..6c8d0e9 100644 --- a/lib/DBIx/Class/Exception.pm +++ b/lib/DBIx/Class/Exception.pm @@ -4,7 +4,6 @@ use strict; use warnings; use Carp::Clan qw/^DBIx::Class|^Try::Tiny/; -use Scalar::Util qw/blessed/; use Try::Tiny; use namespace::clean; @@ -52,7 +51,7 @@ sub throw { my ($class, $msg, $stacktrace) = @_; # Don't re-encapsulate exception objects of any kind - die $msg if blessed($msg); + die $msg if ref($msg); # use Carp::Clan's croak if we're not stack tracing if(!$stacktrace) { diff --git a/t/33exception_wrap.t b/t/33exception_wrap.t new file mode 100644 index 0000000..fdee230 --- /dev/null +++ b/t/33exception_wrap.t @@ -0,0 +1,26 @@ +use strict; +use warnings; + +use Test::More; +use Test::Exception; + +use lib qw(t/lib); + +use DBICTest; +my $schema = DBICTest->init_schema; + +throws_ok (sub { + $schema->txn_do (sub { die 'lol' } ); +}, 'DBIx::Class::Exception', 'a DBIC::Exception object thrown'); + +throws_ok (sub { + $schema->txn_do (sub { die [qw/lol wut/] }); +}, qr/ARRAY\(0x/, 'An arrayref thrown'); + +is_deeply ( + $@, + [qw/ lol wut /], + 'Exception-arrayref contents preserved', +); + +done_testing;