Make LocalFileLockError an error page exception
authorAaron Schulz <aschulz@wikimedia.org>
Wed, 8 Jun 2016 08:10:02 +0000 (01:10 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Sat, 11 Jun 2016 03:00:09 +0000 (03:00 +0000)
This presents a better message than a cryptic red exception hash box

Bug: T132921
Change-Id: Ie3f358378af54d0348f18cfb1df763a182259906

includes/filerepo/file/LocalFile.php

index c767078..2c846e5 100644 (file)
@@ -1920,17 +1920,12 @@ class LocalFile extends File {
                        // Also, that would cause contention on INSERT of similarly named rows.
                        $backend = $this->getRepo()->getBackend();
                        $lockPaths = [ $this->getPath() ]; // represents all versions of the file
-                       $start = microtime( true );
                        $status = $backend->lockFiles( $lockPaths, LockManager::LOCK_EX, 10 );
-                       $waited = microtime( true ) - $start;
                        if ( !$status->isGood() ) {
                                if ( $this->lockedOwnTrx ) {
                                        $dbw->rollback( __METHOD__ );
                                }
-                               throw new LocalFileLockError(
-                                       "Could not acquire lock for '{$this->getName()}' ($waited sec): " .
-                                       $status->getWikiText( false, false, 'en' )
-                               );
+                               throw new LocalFileLockError( $status );
                        }
                        // Release the lock *after* commit to avoid row-level contention
                        $this->locked++;
@@ -3047,6 +3042,17 @@ class LocalFileMoveBatch {
        }
 }
 
-class LocalFileLockError extends Exception {
+class LocalFileLockError extends ErrorPageError {
+       public function __construct( Status $status ) {
+               parent::__construct(
+                       'actionfailed',
+                       $status->getMessage()
+               );
+       }
 
+       public function report() {
+               global $wgOut;
+               $wgOut->setStatusCode( 429 );
+               parent::report();
+       }
 }