r90021 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r90020‎ | r90021 | r90022 >
Date:23:43, 13 June 2011
Author:demon
Status:ok (Comments)
Tags:
Comment:
Convert a couple of wfDie()s to exceptions
Modified paths:
  • /trunk/phase3/tests/parser/parserTest.inc (modified) (history)
  • /trunk/phase3/tests/testHelpers.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/testHelpers.inc
@@ -75,7 +75,7 @@
7676 if ( $this->total > 0 ) {
7777 $this->reportPercentage( $this->success, $this->total );
7878 } else {
79 - wfDie( "No tests found.\n" );
 79+ throw new MWException( "No tests found.\n" );
8080 }
8181 }
8282
@@ -458,7 +458,7 @@
459459 $this->fh = fopen( $this->file, "rt" );
460460
461461 if ( !$this->fh ) {
462 - wfDie( "Couldn't open file '$file'\n" );
 462+ throw new MWException( "Couldn't open file '$file'\n" );
463463 }
464464
465465 $this->parserTest = $parserTest;
@@ -469,7 +469,7 @@
470470
471471 function rewind() {
472472 if ( fseek( $this->fh, 0 ) ) {
473 - wfDie( "Couldn't fseek to the start of '$this->file'\n" );
 473+ throw new MWException( "Couldn't fseek to the start of '$this->file'\n" );
474474 }
475475
476476 $this->index = -1;
@@ -514,11 +514,11 @@
515515
516516 if ( $section == 'endarticle' ) {
517517 if ( !isset( $data['text'] ) ) {
518 - wfDie( "'endarticle' without 'text' at line {$this->lineNum} of $this->file\n" );
 518+ throw new MWException( "'endarticle' without 'text' at line {$this->lineNum} of $this->file\n" );
519519 }
520520
521521 if ( !isset( $data['article'] ) ) {
522 - wfDie( "'endarticle' without 'article' at line {$this->lineNum} of $this->file\n" );
 522+ throw new MWException( "'endarticle' without 'article' at line {$this->lineNum} of $this->file\n" );
523523 }
524524
525525 $this->parserTest->addArticle( ParserTest::chomp( $data['article'] ), $data['text'], $this->lineNum );
@@ -531,7 +531,7 @@
532532
533533 if ( $section == 'endhooks' ) {
534534 if ( !isset( $data['hooks'] ) ) {
535 - wfDie( "'endhooks' without 'hooks' at line {$this->lineNum} of $this->file\n" );
 535+ throw new MWException( "'endhooks' without 'hooks' at line {$this->lineNum} of $this->file\n" );
536536 }
537537
538538 foreach ( explode( "\n", $data['hooks'] ) as $line ) {
@@ -552,7 +552,7 @@
553553
554554 if ( $section == 'endfunctionhooks' ) {
555555 if ( !isset( $data['functionhooks'] ) ) {
556 - wfDie( "'endfunctionhooks' without 'functionhooks' at line {$this->lineNum} of $this->file\n" );
 556+ throw new MWException( "'endfunctionhooks' without 'functionhooks' at line {$this->lineNum} of $this->file\n" );
557557 }
558558
559559 foreach ( explode( "\n", $data['functionhooks'] ) as $line ) {
@@ -573,15 +573,15 @@
574574
575575 if ( $section == 'end' ) {
576576 if ( !isset( $data['test'] ) ) {
577 - wfDie( "'end' without 'test' at line {$this->lineNum} of $this->file\n" );
 577+ throw new MWException( "'end' without 'test' at line {$this->lineNum} of $this->file\n" );
578578 }
579579
580580 if ( !isset( $data['input'] ) ) {
581 - wfDie( "'end' without 'input' at line {$this->lineNum} of $this->file\n" );
 581+ throw new MWException( "'end' without 'input' at line {$this->lineNum} of $this->file\n" );
582582 }
583583
584584 if ( !isset( $data['result'] ) ) {
585 - wfDie( "'end' without 'result' at line {$this->lineNum} of $this->file\n" );
 585+ throw new MWException( "'end' without 'result' at line {$this->lineNum} of $this->file\n" );
586586 }
587587
588588 if ( !isset( $data['options'] ) ) {
@@ -611,7 +611,7 @@
612612 }
613613
614614 if ( isset ( $data[$section] ) ) {
615 - wfDie( "duplicate section '$section' at line {$this->lineNum} of $this->file\n" );
 615+ throw new MWException( "duplicate section '$section' at line {$this->lineNum} of $this->file\n" );
616616 }
617617
618618 $data[$section] = '';
Index: trunk/phase3/tests/parser/parserTest.inc
@@ -1138,14 +1138,13 @@
11391139 $title = Title::newFromText( $name );
11401140
11411141 if ( is_null( $title ) ) {
1142 - wfDie( "invalid title ('$name' => '$title') at line $line\n" );
 1142+ throw new MWException( "invalid title ('$name' => '$title') at line $line\n" );
11431143 }
11441144
11451145 $aid = $title->getArticleID( Title::GAID_FOR_UPDATE );
11461146
11471147 if ( $aid != 0 ) {
1148 - debug_print_backtrace();
1149 - wfDie( "duplicate article '$name' at line $line\n" );
 1148+ throw new MWException( "duplicate article '$name' at line $line\n" );
11501149 }
11511150
11521151 $art = new Article( $title );

Comments

#Comment by Nikerabbit (talk | contribs)   12:26, 14 June 2011

Do we get backtraces on cli?

#Comment by 😂 (talk | contribs)   12:27, 14 June 2011

If $wgShowExceptionDetails is enabled, just like in the UI.

Status & tagging log