From: Peter Rabbitson Date: Wed, 30 Mar 2016 14:06:48 +0000 (+0200) Subject: Fix incorrect exception propagation in ::Replicated::execute_reliably X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=67cbc0a8171b13f8c90ec5c5184d598a3b63e007;p=dbsrgits%2FDBIx-Class-Historic.git Fix incorrect exception propagation in ::Replicated::execute_reliably The code makes no sense in its current state, lapse left in after 1abccf54 --- diff --git a/Changes b/Changes index 07bb206..e6dc25f 100644 --- a/Changes +++ b/Changes @@ -43,6 +43,8 @@ Revision history for DBIx::Class commit message for description of exact failure scenario) - Fix corner case of stringify-only overloaded objects being used in create()/populate() + - Remove spurious exception warping in ::Replicated::execute_reliably + (RT#113339) - Fix spurious ROLLBACK statements when a TxnScopeGuard fails a commit of a transaction with deferred FK checks: a guard is now inactivated immediately before the commit is attempted (RT#107159) diff --git a/lib/DBIx/Class/Storage/DBI/Replicated.pm b/lib/DBIx/Class/Storage/DBI/Replicated.pm index 73998d2..512c53e 100644 --- a/lib/DBIx/Class/Storage/DBI/Replicated.pm +++ b/lib/DBIx/Class/Storage/DBI/Replicated.pm @@ -693,19 +693,13 @@ sub execute_reliably { my $self = shift; my $coderef = shift; - unless( ref $coderef eq 'CODE') { - $self->throw_exception('Second argument must be a coderef'); - } + $self->throw_exception('Second argument must be a coderef') + unless( ref $coderef eq 'CODE'); ## replace the current read handler for the remainder of the scope local $self->{read_handler} = $self->master; - my $args = \@_; - return dbic_internal_try { - $coderef->(@$args); - } catch { - $self->throw_exception("coderef returned an error: $_"); - }; + &$coderef; } =head2 set_reliable_storage diff --git a/t/storage/replicated.t b/t/storage/replicated.t index 9ecc7e8..59bf7e5 100644 --- a/t/storage/replicated.t +++ b/t/storage/replicated.t @@ -709,9 +709,19 @@ ok my $reliably = sub { is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}"; + $_[1] = 9; + } => 'created coderef properly'; -$replicated->schema->storage->execute_reliably($reliably); +my @list_to_mangle = (1, 2, 3); + +$replicated->schema->storage->execute_reliably($reliably, @list_to_mangle); + +is_deeply + \@list_to_mangle, + [ 1, 9, 3], + 'Aliasing of values passed to execute_reliably works' +; ## Try something with an error @@ -726,6 +736,12 @@ throws_ok {$replicated->schema->storage->execute_reliably($unreliably)} qr/Can't find source for ArtistXX/ => 'Bad coderef throws proper error'; +throws_ok { + $replicated->schema->storage->execute_reliably(sub{ + die bless [], 'SomeExceptionThing'; + }); +} 'SomeExceptionThing', "Blessed exception kept intact"; + ## Make sure replication came back ok $replicated->schema->resultset('Artist')->find(3)