From c61d48f87eae0f611e4a09dd16d71385df5b88a9 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Wed, 19 Jun 2013 13:52:33 -0700 Subject: [PATCH] Stop spamming exception log with random upload stash failures * Things like authorization and validation problems do not belong in the exception log. Change-Id: I3c4c1bab65cfe9111dc2161bda6d023234112900 --- includes/AutoLoader.php | 1 + includes/api/ApiUpload.php | 23 ++++++++++++++++------- includes/upload/UploadStash.php | 17 +++++++++-------- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index ba9f962ab5..6f8cd4bc9c 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -1021,6 +1021,7 @@ $wgAutoloadLocalClasses = array( 'UploadFromUrl' => 'includes/upload/UploadFromUrl.php', 'UploadStash' => 'includes/upload/UploadStash.php', 'UploadStashBadPathException' => 'includes/upload/UploadStash.php', + 'UploadStashException' => 'includes/upload/UploadStash.php', 'UploadStashFile' => 'includes/upload/UploadStash.php', 'UploadStashFileException' => 'includes/upload/UploadStash.php', 'UploadStashFileNotFoundException' => 'includes/upload/UploadStash.php', diff --git a/includes/api/ApiUpload.php b/includes/api/ApiUpload.php index 8f71fbe6a2..34741b553b 100644 --- a/includes/api/ApiUpload.php +++ b/includes/api/ApiUpload.php @@ -61,10 +61,14 @@ class ApiUpload extends ApiBase { } // Select an upload module - if ( !$this->selectUploadModule() ) { - return; // not a true upload, but a status request or similar - } elseif ( !isset( $this->mUpload ) ) { - $this->dieUsage( 'No upload module set', 'nomodule' ); + try { + if ( !$this->selectUploadModule() ) { + return; // not a true upload, but a status request or similar + } elseif ( !isset( $this->mUpload ) ) { + $this->dieUsage( 'No upload module set', 'nomodule' ); + } + } catch ( UploadStashException $e ) { // XXX: don't spam exception log + $this->dieUsage( get_class( $e ) . ": " . $e->getMessage(), 'stasherror' ); } // First check permission to upload @@ -106,9 +110,13 @@ class ApiUpload extends ApiBase { } // Get the result based on the current upload context: - $result = $this->getContextResult(); - if ( $result['result'] === 'Success' ) { - $result['imageinfo'] = $this->mUpload->getImageInfo( $this->getResult() ); + try { + $result = $this->getContextResult(); + if ( $result['result'] === 'Success' ) { + $result['imageinfo'] = $this->mUpload->getImageInfo( $this->getResult() ); + } + } catch ( UploadStashException $e ) { // XXX: don't spam exception log + $this->dieUsage( get_class( $e ) . ": " . $e->getMessage(), 'stasherror' ); } $this->getResult()->addValue( null, $this->getModuleName(), $result ); @@ -807,6 +815,7 @@ class ApiUpload extends ApiBase { array( 'code' => 'publishfailed', 'info' => 'Publishing of stashed file failed' ), array( 'code' => 'internal-error', 'info' => 'An internal error occurred' ), array( 'code' => 'asynccopyuploaddisabled', 'info' => 'Asynchronous copy uploads disabled' ), + array( 'code' => 'stasherror', 'info' => 'An upload stash error occurred' ), array( 'fileexists-forbidden' ), array( 'fileexists-shared-forbidden' ), ) diff --git a/includes/upload/UploadStash.php b/includes/upload/UploadStash.php index 8a6d766912..ebeb9c188d 100644 --- a/includes/upload/UploadStash.php +++ b/includes/upload/UploadStash.php @@ -675,11 +675,12 @@ class UploadStashFile extends UnregisteredLocalFile { } -class UploadStashNotAvailableException extends MWException {}; -class UploadStashFileNotFoundException extends MWException {}; -class UploadStashBadPathException extends MWException {}; -class UploadStashFileException extends MWException {}; -class UploadStashZeroLengthFileException extends MWException {}; -class UploadStashNotLoggedInException extends MWException {}; -class UploadStashWrongOwnerException extends MWException {}; -class UploadStashNoSuchKeyException extends MWException {}; +class UploadStashException extends MWException {}; +class UploadStashNotAvailableException extends UploadStashException {}; +class UploadStashFileNotFoundException extends UploadStashException {}; +class UploadStashBadPathException extends UploadStashException {}; +class UploadStashFileException extends UploadStashException {}; +class UploadStashZeroLengthFileException extends UploadStashException {}; +class UploadStashNotLoggedInException extends UploadStashException {}; +class UploadStashWrongOwnerException extends UploadStashException {}; +class UploadStashNoSuchKeyException extends UploadStashException {}; -- 2.20.1