r111571 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111570‎ | r111571 | r111572 >
Date:20:06, 15 February 2012
Author:aaron
Status:ok
Tags:
Comment:
Put the filename in more of the exceptions thrown
Modified paths:
  • /trunk/phase3/includes/Cdb_PHP.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Cdb_PHP.php
@@ -82,6 +82,9 @@
8383 * CDB reader class
8484 */
8585 class CdbReader_PHP extends CdbReader {
 86+ /** The filename */
 87+ var $fileName;
 88+
8689 /** The file handle */
8790 var $handle;
8891
@@ -110,9 +113,10 @@
111114 * @param $fileName string
112115 */
113116 function __construct( $fileName ) {
 117+ $this->fileName = $fileName;
114118 $this->handle = fopen( $fileName, 'rb' );
115119 if ( !$this->handle ) {
116 - throw new MWException( 'Unable to open CDB file "' . $fileName . '"' );
 120+ throw new MWException( 'Unable to open CDB file "' . $this->fileName . '".' );
117121 }
118122 $this->findStart();
119123 }
@@ -160,7 +164,8 @@
161165 protected function read( $length, $pos ) {
162166 if ( fseek( $this->handle, $pos ) == -1 ) {
163167 // This can easily happen if the internal pointers are incorrect
164 - throw new MWException( __METHOD__.': seek failed, file may be corrupted.' );
 168+ throw new MWException(
 169+ 'Seek failed, file "' . $this->fileName . '" may be corrupted.' );
165170 }
166171
167172 if ( $length == 0 ) {
@@ -169,7 +174,8 @@
170175
171176 $buf = fread( $this->handle, $length );
172177 if ( $buf === false || strlen( $buf ) !== $length ) {
173 - throw new MWException( __METHOD__.': read from CDB file failed, file may be corrupted' );
 178+ throw new MWException(
 179+ 'Read from CDB file failed, file "' . $this->fileName . '" may be corrupted.' );
174180 }
175181 return $buf;
176182 }
@@ -182,7 +188,8 @@
183189 protected function unpack31( $s ) {
184190 $data = unpack( 'V', $s );
185191 if ( $data[1] > 0x7fffffff ) {
186 - throw new MWException( __METHOD__.': error in CDB file, integer too big' );
 192+ throw new MWException(
 193+ 'Error in CDB file "' . $this->fileName . '", integer too big.' );
187194 }
188195 return $data[1];
189196 }
@@ -270,13 +277,15 @@
271278 $this->tmpFileName = $fileName . '.tmp.' . mt_rand( 0, 0x7fffffff );
272279 $this->handle = fopen( $this->tmpFileName, 'wb' );
273280 if ( !$this->handle ) {
274 - throw new MWException( 'Unable to open CDB file for write "' . $fileName . '"' );
 281+ throw new MWException(
 282+ 'Unable to open CDB file "' . $this->tmpFileName . '" for write.' );
275283 }
276284 $this->hplist = array();
277285 $this->numentries = 0;
278286 $this->pos = 2048; // leaving space for the pointer array, 256 * 8
279287 if ( fseek( $this->handle, $this->pos ) == -1 ) {
280 - throw new MWException( __METHOD__.': fseek failed' );
 288+ throw new MWException(
 289+ 'fseek failed in file "' . $this->tmpFileName . '".' );
281290 }
282291 }
283292
@@ -326,7 +335,7 @@
327336 protected function write( $buf ) {
328337 $len = fwrite( $this->handle, $buf );
329338 if ( $len !== strlen( $buf ) ) {
330 - throw new MWException( 'Error writing to CDB file.' );
 339+ throw new MWException( 'Error writing to CDB file "'.$this->tmpFileName.'".' );
331340 }
332341 }
333342
@@ -337,7 +346,8 @@
338347 protected function posplus( $len ) {
339348 $newpos = $this->pos + $len;
340349 if ( $newpos > 0x7fffffff ) {
341 - throw new MWException( 'A value in the CDB file is too large' );
 350+ throw new MWException(
 351+ 'A value in the CDB file "'.$this->tmpFileName.'" is too large.' );
342352 }
343353 $this->pos = $newpos;
344354 }
@@ -366,10 +376,10 @@
367377 */
368378 protected function addbegin( $keylen, $datalen ) {
369379 if ( $keylen > 0x7fffffff ) {
370 - throw new MWException( __METHOD__.': key length too long' );
 380+ throw new MWException( 'Key length too long in file "'.$this->tmpFileName.'".' );
371381 }
372382 if ( $datalen > 0x7fffffff ) {
373 - throw new MWException( __METHOD__.': data length too long' );
 383+ throw new MWException( 'Data length too long in file "'.$this->tmpFileName.'".' );
374384 }
375385 $buf = pack( 'VV', $keylen, $datalen );
376386 $this->write( $buf );
@@ -444,7 +454,7 @@
445455 // Write the pointer array at the start of the file
446456 rewind( $this->handle );
447457 if ( ftell( $this->handle ) != 0 ) {
448 - throw new MWException( __METHOD__.': Error rewinding to start of file' );
 458+ throw new MWException( 'Error rewinding to start of file "'.$this->tmpFileName.'".' );
449459 }
450460 $this->write( $final );
451461 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r111581MFT r111043, r111484, r111571, r111574, r111575reedy20:46, 15 February 2012
r111770MFT r111478, r111571, r111574, r111597, r111658reedy18:15, 17 February 2012

Status & tagging log