From: Peter Rabbitson Date: Wed, 30 Mar 2016 14:06:48 +0000 (+0200) Subject: Fix incorrect exception propagation in ::Replicated::execute_reliably X-Git-Tag: v0.082840~21 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FDBIx-Class.git;a=commitdiff_plain;h=294c6f29842319f3f8ddcd215d770ea980d6a494 Fix incorrect exception propagation in ::Replicated::execute_reliably ( cherry-pick of 67cbc0a817 ) The code makes no sense in its current state, lapse left in after 1abccf54 --- diff --git a/Changes b/Changes index 60ae978..fbb0daa 100644 --- a/Changes +++ b/Changes @@ -7,6 +7,8 @@ Revision history for DBIx::Class $dbh->{HandleError} (GH#101) - Fix parsing of DSNs containing driver arguments (GH#99) - Fix spurious warning on MSSQL cursor invalidation retries (RT#102166) + - Remove spurious exception warping in ::Replicated::execute_reliably + (RT#113339) - Work around unreliable $sth->finish() on INSERT ... RETURNING within DBD::Firebird on some compiler/driver combinations (RT#110979) - Fix leaktest failures with upcoming version of Sub::Quote diff --git a/lib/DBIx/Class/Storage/DBI/Replicated.pm b/lib/DBIx/Class/Storage/DBI/Replicated.pm index 6b1181e..c55c2d9 100644 --- a/lib/DBIx/Class/Storage/DBI/Replicated.pm +++ b/lib/DBIx/Class/Storage/DBI/Replicated.pm @@ -685,19 +685,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 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 b735e0f..95a6d9f 100644 --- a/t/storage/replicated.t +++ b/t/storage/replicated.t @@ -713,9 +713,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 @@ -730,6 +740,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)