From: Brion Vibber Date: Thu, 6 Dec 2007 21:07:49 +0000 (+0000) Subject: * (bug 12184) Exceptions now sent to stderr instead of stdout for command-line X-Git-Tag: 1.31.0-rc.0~50517 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/comptes/ajouter.php?a=commitdiff_plain;h=60c13d2853c5522e48081a4b8712532741362d34;p=lhc%2Fweb%2Fwiklou.git * (bug 12184) Exceptions now sent to stderr instead of stdout for command-line scripts, making for cleaner reporting during batch jobs. PHP errors will also be redirected in most cases on PHP 5.2.4 and later, switching 'display_errors' to 'stderr' at runtime. --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index be0b761e59..fd92d07bdd 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -219,6 +219,11 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * (bug 11993) Remove contentsub "revision history" * (bug 11952) Ensure we quote_ident() all schema names as needed inside of the DatabasePostgres.php file. +* (bug 12184) Exceptions now sent to stderr instead of stdout for command-line + scripts, making for cleaner reporting during batch jobs. PHP errors will also + be redirected in most cases on PHP 5.2.4 and later, switching 'display_errors' + to 'stderr' at runtime. + == Parser changes in 1.12 == diff --git a/includes/Exception.php b/includes/Exception.php index 06cadc0df2..1ae28deeca 100644 --- a/includes/Exception.php +++ b/includes/Exception.php @@ -94,7 +94,7 @@ class MWException extends Exception /** Print the exception report using text */ function reportText() { - echo $this->getText(); + fwrite( STDERR, $this->getText() ); } /* Output a report about the exception and takes care of formatting. @@ -200,7 +200,7 @@ function wfReportException( Exception $e ) { $e2->__toString() . "\n"; if ( !empty( $GLOBALS['wgCommandLineMode'] ) ) { - echo $message; + fwrite( STDERR, $message ); } else { echo nl2br( htmlspecialchars( $message ) ). "\n"; } diff --git a/maintenance/backup.inc b/maintenance/backup.inc index ee44954ca4..94fb48c9ae 100644 --- a/maintenance/backup.inc +++ b/maintenance/backup.inc @@ -170,7 +170,8 @@ class BackupDumper { function dump( $history, $text = MW_EXPORT_TEXT ) { # Notice messages will foul up your XML output even if they're # relatively harmless. - ini_set( 'display_errors', false ); + if( ini_get( 'display_errors' ) ) + ini_set( 'display_errors', 'stderr' ); $this->initProgress( $history ); diff --git a/maintenance/commandLine.inc b/maintenance/commandLine.inc index 4466344fe7..f7bb53ff5a 100644 --- a/maintenance/commandLine.inc +++ b/maintenance/commandLine.inc @@ -216,6 +216,20 @@ if ( defined( 'MW_CMDLINE_CALLBACK' ) ) { ini_set( 'memory_limit', -1 ); +if( version_compare( phpversion(), '5.2.4' ) >= 0 ) { + // Send PHP warnings and errors to stderr instead of stdout. + // This aids in diagnosing problems, while keeping messages + // out of redirected output. + if( ini_get( 'display_errors' ) ) { + ini_set( 'display_errors', 'stderr' ); + } + + // Don't touch the setting on earlier versions of PHP, + // as setting it would disable output if you'd wanted it. + + // Note that exceptions are also sent to stderr when + // command-line mode is on, regardless of PHP version. +} $wgShowSQLErrors = true; require_once( "$IP/includes/Setup.php" ); diff --git a/maintenance/dumpTextPass.php b/maintenance/dumpTextPass.php index 827c49378e..703fa1e53b 100644 --- a/maintenance/dumpTextPass.php +++ b/maintenance/dumpTextPass.php @@ -118,7 +118,8 @@ class TextPassDumper extends BackupDumper { # Notice messages will foul up your XML output even if they're # relatively harmless. -// ini_set( 'display_errors', false ); + if( ini_get( 'display_errors' ) ) + ini_set( 'display_errors', 'stderr' ); $this->initProgress( $this->history );