Fix missing handling of on_(dis)connect* failures
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI.pm
index 25a4513..abd9e9d 100644 (file)
@@ -1115,6 +1115,10 @@ sub _server_info {
   # this confuses CXSA: https://rt.cpan.org/Ticket/Display.html?id=103296
   $self->_dbh_details->{info} || do {
 
+    # this guarantees that problematic conninfo won't be hidden
+    # by the try{} below
+    $self->ensure_connected;
+
     my $info = {};
 
     my $server_version = try {
@@ -1373,6 +1377,7 @@ sub _warn_undetermined_driver {
 sub _do_connection_actions {
   my ($self, $method_prefix, $call, @args) = @_;
 
+  try {
     if (not ref($call)) {
       my $method = $method_prefix . $call;
       $self->$method(@args);
@@ -1391,6 +1396,19 @@ sub _do_connection_actions {
     else {
       $self->throw_exception (sprintf ("Don't know how to process conection actions of type '%s'", ref($call)) );
     }
+  }
+  catch {
+    if ( $method_prefix =~ /^connect/ ) {
+      # this is an on_connect cycle - we can't just throw while leaving
+      # a handle in an undefined state in our storage object
+      # kill it with fire and rethrow
+      $self->_dbh(undef);
+      $self->throw_exception( $_[0] );
+    }
+    else {
+      carp "Disconnect action failed: $_[0]";
+    }
+  };
 
   return $self;
 }