r74701 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r74700‎ | r74701 | r74702 >
Date:00:13, 13 October 2010
Author:neilk
Status:resolved (Comments)
Tags:
Comment:
better error reporting in exceptions; making getDescriptionUrl for SessionStashFile a real url since it breaks the image convert call on some platforms if it's the empty string
Modified paths:
  • /branches/uploadwizard/extensions/UploadWizard/ApiQueryStashImageInfo.php (modified) (history)
  • /branches/uploadwizard/phase3/includes/upload/SessionStash.php (modified) (history)

Diff [purge]

Index: branches/uploadwizard/phase3/includes/upload/SessionStash.php
@@ -39,7 +39,7 @@
4040 $this->repo = $repo;
4141
4242 if ( ! isset( $_SESSION ) ) {
43 - throw new SessionStashNotAvailableException( 'no session var' );
 43+ throw new SessionStashNotAvailableException( 'no session variable' );
4444 }
4545
4646 if ( !isset( $_SESSION[UploadBase::SESSION_KEYNAME] ) ) {
@@ -68,13 +68,13 @@
6969 public function getFile( $key ) {
7070 if ( !isset( $this->files[$key] ) ) {
7171 if ( !isset( $_SESSION[UploadBase::SESSION_KEYNAME][$key] ) ) {
72 - throw new SessionStashFileNotFoundException();
 72+ throw new SessionStashFileNotFoundException( "key '$key' not found in session" );
7373 }
7474
7575 $data = $_SESSION[UploadBase::SESSION_KEYNAME][$key];
7676 // guards against PHP class changing while session data doesn't
7777 if ($data['version'] !== UploadBase::SESSION_VERSION ) {
78 - throw new SessionStashBadVersionException();
 78+ throw new SessionStashBadVersionException( $data['version'] . " does not match current version " . UploadBase::SESSION_VERSION );
7979 }
8080
8181 // separate the stashData into the path, and then the rest of the data
@@ -82,6 +82,7 @@
8383 unset( $data['mTempPath'] );
8484
8585 $file = new SessionStashFile( $this, $this->repo, $path, $key, $data );
 86+
8687 $this->files[$key] = $file;
8788
8889 }
@@ -100,7 +101,7 @@
101102 */
102103 public function stashFile( $path, $data = array(), $key = null ) {
103104 if ( ! file_exists( $path ) ) {
104 - throw new SessionStashBadPathException();
 105+ throw new SessionStashBadPathException( "path '$path' doesn't exist" );
105106 }
106107 $fileProps = File::getPropsFromPath( $path );
107108
@@ -157,21 +158,22 @@
158159 $this->sessionStash = $stash;
159160 $this->sessionKey = $key;
160161 $this->sessionData = $data;
161 -
 162+
162163 // resolve mwrepo:// urls
163164 if ( $repo->isVirtualUrl( $path ) ) {
164165 $path = $repo->resolveVirtualUrl( $path );
165166 }
166167
167168 // check if path appears to be sane, no parent traversals, and is in this repo's temp zone.
 169+ $repoTempPath = $repo->getZonePath( 'temp' );
168170 if ( ( ! $repo->validateFilename( $path ) ) ||
169 - ( strpos( $path, $repo->getZonePath( 'temp' ) ) !== 0 ) ) {
170 - throw new SessionStashBadPathException();
 171+ ( strpos( $path, $repoTempPath ) !== 0 ) ) {
 172+ throw new SessionStashBadPathException( "path '$path' is not valid or is not in repo temp area: '$repoTempPath'" );
171173 }
172174
173175 // check if path exists! and is a plain file.
174176 if ( ! $repo->fileExists( $path, FileRepo::FILES_ONLY ) ) {
175 - throw new SessionStashFileNotFoundException();
 177+ throw new SessionStashFileNotFoundException( "cannot find path '$path'" );
176178 }
177179
178180 parent::__construct( false, $repo, $path, false );
@@ -186,10 +188,12 @@
187189 /**
188190 * A method needed by the file transforming and scaling routines in File.php
189191 * We do not necessarily care about doing the description at this point
190 - * @return {String} the empty string
 192+ * However, we also can't return the empty string, as the rest of MediaWiki demands this (and calls to imagemagick
 193+ * convert require it to be there)
 194+ * @return {String} dummy value
191195 */
192196 public function getDescriptionUrl() {
193 - return '';
 197+ return $this->getUrl();
194198 }
195199
196200 /**
@@ -220,7 +224,7 @@
221225 }
222226
223227 if ( is_null( $extension ) ) {
224 - throw new SessionStashFileException();
 228+ throw new SessionStashFileException( "extension '$extension' is null" );
225229 }
226230
227231 $this->extension = parent::normalizeExtension( $extension );
Index: branches/uploadwizard/extensions/UploadWizard/ApiQueryStashImageInfo.php
@@ -60,11 +60,11 @@
6161 }
6262
6363 } catch ( SessionStashNotAvailableException $e ) {
64 - $this->dieUsage( "Session not available", "nosession" );
 64+ $this->dieUsage( "Session not available: " . $e->getMessage(), "nosession" );
6565 } catch ( SessionStashFileNotFoundException $e ) {
66 - $this->dieUsage( "File not found", "nosuchpageid" );
 66+ $this->dieUsage( "File not found: " . $e->getMessage(), "nosuchpageid" );
6767 } catch ( SessionStashBadPathException $e ) {
68 - $this->dieUsage( "Bad path", "nosuchpageid" );
 68+ $this->dieUsage( "Bad path: " . $e->getMessage(), "nosuchpageid" );
6969 }
7070
7171 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r74999followup to r74701, better error messageneilk04:49, 19 October 2010

Comments

#Comment by Catrope (talk | contribs)   17:13, 16 October 2010
-			$this->dieUsage( "File not found", "nosuchpageid" );
+			$this->dieUsage( "File not found: " . $e->getMessage(), "nosuchpageid" );
 		} catch ( SessionStashBadPathException $e ) {
-			$this->dieUsage( "Bad path", "nosuchpageid" );
+			$this->dieUsage( "Bad path: " . $e->getMessage(), "nosuchpageid" );

You should use descriptive error codes rather than the misleading "nosuchpageid". You can make up any error code you want.

#Comment by NeilK (talk | contribs)   04:50, 19 October 2010

'invalid-session-key' seems to cover both better, committed in r74999

#Comment by NeilK (talk | contribs)   04:50, 19 October 2010

er, I meant to say 'invalidsessiondata'.

Status & tagging log