doMaintenance: Try to print errors to stderr
authorMarius Hoch <hoo@online.de>
Tue, 16 Jul 2019 11:15:57 +0000 (13:15 +0200)
committerMarius Hoch <hoo@online.de>
Tue, 16 Jul 2019 11:15:57 +0000 (13:15 +0200)
Don't mix them in with stdout (which might be redirected,
like dump output, making the errors hard to discover).

Change-Id: Ibed8c0e8dde3e44de60bf32abd3fc5ce5d29e1ba

maintenance/doMaintenance.php

index 0ee1e6a..fe4905b 100644 (file)
@@ -99,12 +99,20 @@ try {
        $success = $maintenance->execute();
 } catch ( Exception $ex ) {
        $success = false;
+       $exReportMessage = '';
        while ( $ex ) {
                $cls = get_class( $ex );
-               print "$cls from line {$ex->getLine()} of {$ex->getFile()}: {$ex->getMessage()}\n";
-               print $ex->getTraceAsString() . "\n";
+               $exReportMessage .= "$cls from line {$ex->getLine()} of {$ex->getFile()}: {$ex->getMessage()}\n";
+               $exReportMessage .= $ex->getTraceAsString() . "\n";
                $ex = $ex->getPrevious();
        }
+       // Print the exception to stderr if possible, don't mix it in
+       // with stdout output.
+       if ( defined( 'STDERR' ) ) {
+               fwrite( STDERR, $exReportMessage );
+       } else {
+               echo $exReportMessage;
+       }
 }
 
 // Potentially debug globals