From 3f7fa975e03add4f6d57a98e54fcef8c49712676 Mon Sep 17 00:00:00 2001 From: Marius Hoch Date: Tue, 16 Jul 2019 13:15:57 +0200 Subject: [PATCH] doMaintenance: Try to print errors to stderr 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 | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/maintenance/doMaintenance.php b/maintenance/doMaintenance.php index 0ee1e6a0b8..fe4905b228 100644 --- a/maintenance/doMaintenance.php +++ b/maintenance/doMaintenance.php @@ -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 -- 2.20.1