Handle CDB errors more gracefully in cdb.php maintenance script
authorChad Horohoe <chadh@wikimedia.org>
Thu, 21 Nov 2013 23:22:47 +0000 (15:22 -0800)
committerChad Horohoe <chadh@wikimedia.org>
Thu, 21 Nov 2013 23:23:36 +0000 (15:23 -0800)
Change-Id: I9be42c909c85cd454fdd10921c8d50d6273252f8

maintenance/cdb.php

index d42f9f7..bda64f3 100644 (file)
@@ -75,7 +75,10 @@ do {
                        }
                        $file = $args[0];
                        print "Loading cdb file $file...";
-                       $fileHandle = CdbReader::open( $file );
+                       try {
+                               $fileHandle = CdbReader::open( $file );
+                       } catch( CdbException $e ) {}
+
                        if ( !$fileHandle ) {
                                print "not a cdb file or unable to read it\n";
                        } else {
@@ -91,7 +94,11 @@ do {
                                print "Need to specify a key, Luke\n";
                                break;
                        }
-                       $res = $fileHandle->get( $args[0] );
+                       try {
+                               $res = $fileHandle->get( $args[0] );
+                       } catch ( CdbException $e ) {
+                               print "Unable to read key from file\n";
+                       }
                        if ( $res === false ) {
                                print "No such key/value pair\n";
                        } elseif ( is_string( $res ) ) {