Merge "Add more detailed upload stash error messages"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Wed, 29 Oct 2014 17:40:53 +0000 (17:40 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 29 Oct 2014 17:40:53 +0000 (17:40 +0000)
1  2 
includes/api/ApiUpload.php
languages/i18n/qqq.json

@@@ -64,7 -64,7 +64,7 @@@ class ApiUpload extends ApiBase 
                                $this->dieUsage( 'No upload module set', 'nomodule' );
                        }
                } catch ( UploadStashException $e ) { // XXX: don't spam exception log
-                       $this->dieUsage( get_class( $e ) . ": " . $e->getMessage(), 'stasherror' );
+                       $this->handleStashException( $e );
                }
  
                // First check permission to upload
                                $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->handleStashException( $e );
                }
  
                $this->getResult()->addValue( null, $this->getModuleName(), $result );
                        if ( $warnings && count( $warnings ) > 0 ) {
                                $result['warnings'] = $warnings;
                        }
+               } catch ( UploadStashException $e ) {
+                       $this->handleStashException( $e );
                } catch ( MWException $e ) {
                        $this->dieUsage( $e->getMessage(), 'stashfailed' );
                }
                try {
                        $result['filekey'] = $this->performStash();
                        $result['sessionkey'] = $result['filekey']; // backwards compatibility
+               } catch ( UploadStashException $e ) {
+                       $this->handleStashException( $e );
                } catch ( MWException $e ) {
                        $result['warnings']['stashfailed'] = $e->getMessage();
                }
                if ( $this->mParams['offset'] == 0 ) {
                        try {
                                $filekey = $this->performStash();
+                       } catch ( UploadStashException $e ) {
+                               $this->handleStashException( $e );
                        } catch ( MWException $e ) {
                                // FIXME: Error handling here is wrong/different from rest of this
                                $this->dieUsage( $e->getMessage(), 'stashfailed' );
                } catch ( MWException $e ) {
                        $message = 'Stashing temporary file failed: ' . get_class( $e ) . ' ' . $e->getMessage();
                        wfDebug( __METHOD__ . ' ' . $message . "\n" );
-                       throw new MWException( $message );
+                       $className = get_class( $e );
+                       throw new $className( $message );
                }
  
                return $fileKey;
                return $warnings;
        }
  
+       /**
+        * Handles a stash exception, giving a useful error to the user.
+        * @param Exception $e The exception we encountered.
+        */
+       protected function handleStashException( $e ) {
+               $exceptionType = get_class( $e );
+               switch ( $exceptionType ) {
+                       case 'UploadStashFileNotFoundException':
+                               $this->dieUsage( 'Could not find the file in the stash: ' . $e->getMessage(), 'stashedfilenotfound' );
+                               break;
+                       case 'UploadStashBadPathException':
+                               $this->dieUsage( 'File key of improper format or otherwise invalid: ' . $e->getMessage(), 'stashpathinvalid' );
+                               break;
+                       case 'UploadStashFileException':
+                               $this->dieUsage( 'Could not store upload in the stash: ' . $e->getMessage(), 'stashfilestorage' );
+                               break;
+                       case 'UploadStashZeroLengthFileException':
+                               $this->dieUsage( 'File is of zero length, and could not be stored in the stash: ' . $e->getMessage(), 'stashzerolength' );
+                               break;
+                       case 'UploadStashNotLoggedInException':
+                               $this->dieUsage( 'Not logged in: ' . $e->getMessage(), 'stashnotloggedin' );
+                               break;
+                       case 'UploadStashWrongOwnerException':
+                               $this->dieUsage( 'Wrong owner: ' . $e->getMessage(), 'stashwrongowner' );
+                               break;
+                       case 'UploadStashNoSuchKeyException':
+                               $this->dieUsage( 'No such filekey: ' . $e->getMessage(), 'stashnosuchfilekey' );
+                               break;
+                       default:
+                               $this->dieUsage( $exceptionType . ": " . $e->getMessage(), 'stasherror' );
+                               break;
+               }
+       }
        /**
         * Perform the actual upload. Returns a suitable result array on success;
         * dies on failure.
                return 'csrf';
        }
  
 -      public function getExamplesMessages() {
 +      protected function getExamplesMessages() {
                return array(
                        'action=upload&filename=Wiki.png' .
                                '&url=http%3A//upload.wikimedia.org/wikipedia/en/b/bc/Wiki.png&token=123ABC'
diff --combined languages/i18n/qqq.json
@@@ -75,6 -75,7 +75,7 @@@
                        "MIKHEIL",
                        "Malafaya",
                        "MarkvA",
+                       "marktraceur",
                        "Matma Rex",
                        "MaxSem",
                        "McDutchie",
        "prefs-displayrc": "\"Display\" is a noun that specifies the kind of \"options\". So translate as \"options about display\", not as \"display the options\".\n\nUsed in [[Special:Preferences]], tab \"Recent changes\". The display options refer to:\n* {{msg-mw|Recentchangesdays}}\n* {{msg-mw|Recentchangescount}}",
        "prefs-displaywatchlist": "\"Display\" is a noun that specifies the kind of \"options\". So translate as \"options about display\", not as \"display the options\".\n\nUsed in [[Special:Preferences]], tab \"Watchlist\". The display options refer to:\n* {{msg-mw|Prefs-watchlist-days}}\n* {{msg-mw|Prefs-watchlist-edits}}",
        "prefs-tokenwatchlist": "Section heading.\nUsed in [[Special:Preferences]], tab \"Watchlist\".\n{{Identical|Token}}",
 -      "prefs-diffs": "Used in [[Special:Preferences]], tab \"Misc\".",
 +      "prefs-diffs": "Used in [[Special:Preferences]], tab \"Misc\".\n{{Identical|Diff}}",
        "prefs-help-prefershttps": "Used as help text for the checkbox in [[Special:Preferences]].\n\nThe checkbox has the label {{msg-mw|Tog-prefershttps}}.\n\nSee example: [[mw:Special:Preferences]].",
        "prefswarning-warning": "Warning shown (except in Firefox) when attempting to leave [[Special:Preferences]] with unsaved changes.\n\nParameters:\n* $1 - Text of {{msg-mw|saveprefs}}, as <nowiki>{{int:saveprefs}}</nowiki> cannot be used directly.",
        "prefs-tabs-navigation-hint": "Hint message that explains the arrow key navigation for the tabs on [[Special:Preferences]] to screenreader users.",
        "rcshowhidemine-show": "{{doc-actionlink}}\nOption text in [[Special:RecentChanges]] in conjunction with {{msg-mw|rcshowhidemine}}.\n\nSee also:\n* {{msg-mw|rcshowhidemine-hide}}\n{{Identical|show}}",
        "rcshowhidemine-hide": "{{doc-actionlink}}\nOption text in [[Special:RecentChanges]] in conjunction with {{msg-mw|rcshowhidemine}}.\n\nSee also:\n* {{msg-mw|rcshowhidemine-show}}\n{{Identical|hide}}",
        "rclinks": "Used on [[Special:RecentChanges]].\n* $1 - a list of different choices with number of pages to be shown.<br />&nbsp;Example: \"''50{{int:pipe-separator}}100{{int:pipe-separator}}250{{int:pipe-separator}}500\".\n* $2 - a list of clickable links with a number of days for which recent changes are to be displayed.<br />&nbsp;Example: \"''1{{int:pipe-separator}}3{{int:pipe-separator}}7{{int:pipe-separator}}14{{int:pipe-separator}}30''\".\n* $3 - a block of text that consists of other messages.<br />&nbsp;Example: \"''Hide minor edits{{int:pipe-separator}}Show bots{{int:pipe-separator}}Hide anonymous users{{int:pipe-separator}}Hide logged-in users{{int:pipe-separator}}Hide patrolled edits{{int:pipe-separator}}Hide my edits''\"\nList elements are separated by {{msg-mw|Pipe-separator}} each. Each list element is, or contains, a link.",
 -      "diff": "Short form of \"differences\". Used on [[Special:RecentChanges]], [[Special:Watchlist]], ...",
 +      "diff": "Short form of \"differences\". Used on [[Special:RecentChanges]], [[Special:Watchlist]], ...\n{{Identical|Diff}}",
        "hist": "Short form of \"history\". Used on [[Special:RecentChanges]], [[Special:Watchlist]], ...",
        "hide": "{{doc-actionlink}}\nOption text in [[Special:RecentChanges]], and in [[Special:WhatLinksHere]].\n\nSee also:\n* {{msg-mw|Show}}\n{{Identical|Hide}}",
        "show": "{{doc-actionlink}}\nOption text in [[Special:RecentChanges]], and in [[Special:WhatLinksHere]].\n\nSee also:\n* {{msg-mw|Hide}}\n{{Identical|Show}}",
        "api-error-stashfailed": "API error message that can be used for client side localisation of API errors.",
        "api-error-publishfailed": "API error message that can be used for client side localisation of API errors.",
        "api-error-stasherror": "API error message that can be used for client side localisation of API errors.",
+       "api-error-stashedfilenotfound": "API error message that can be used for client side localisation of API errors.",
+       "api-error-stashpathinvalid": "API error message that can be used for client side localisation of API errors.",
+       "api-error-stashfilestorage": "API error message that can be used for client side localisation of API errors.",
+       "api-error-stashzerolength": "API error message that can be used for client side localisation of API errors.",
+       "api-error-stashnotloggedin": "API error message that can be used for client side localisation of API errors.",
+       "api-error-stashwrongowner": "API error message that can be used for client side localisation of API errors.",
+       "api-error-stashnosuchfilekey": "API error message that can be used for client side localisation of API errors.",
        "api-error-timeout": "API error message that can be used for client side localisation of API errors.",
        "api-error-unclassified": "API error message that can be used for client side localisation of API errors.",
        "api-error-unknown-code": "API error message that can be used for client side localisation of API errors.\n\nParameters:\n* $1 - may contain more error details\n{{Identical|Unknown error}}",
        "mediastatistics-header-executable": "Header on [[Special:MediaStatistics]] for file types that are in the executable category. This includes things like source files for interpreted programming language (Shell scripts, javascript, etc).",
        "mediastatistics-header-archive": "Header on [[Special:MediaStatistics]] for file types that are in the archive category. Includes things like tar, zip, gzip etc.",
        "json-warn-trailing-comma": "A warning message notifying that JSON text was automatically corrected by removing erroneous commas.\n\nParameters:\n* $1 - number of commas that were removed\n{{Related|Json-error}}",
 -      "json-error-unknown": "User error message when there’s an unknown error.\n\nThis error is shown if we received an unexpected value from PHP. See http://php.net/manual/en/function.json-last-error.php\n\nParameters:\n* $1 - integer error code\n{{Related|Json-error}}\n{{Identical|Unknown error}}",
 +      "json-error-unknown": "User error message when there’s an unknown error.\n\nThis error is shown if we received an unexpected value from PHP. See http://php.net/manual/en/function.json-last-error.php\n\nParameters:\n* $1 - integer error code\n{{Related|Json-error}}",
        "json-error-depth": "User error message when the maximum stack depth is exceeded.\nSee http://php.net/manual/en/function.json-last-error.php\n{{Related|Json-error}}",
        "json-error-state-mismatch": "User error message when underflow or the modes mismatch.\n\n'''Underflow''': A data-processing error arising when the absolute value of a computed quantity is smaller than the limits of precision of the computing device, retaining at least one significant digit.\n\nSee http://php.net/manual/en/function.json-last-error.php\n{{Related|Json-error}}",
        "json-error-ctrl-char": "User error message when an unexpected control character has been found.\nSee http://php.net/manual/en/function.json-last-error.php\n{{Related|Json-error}}",