From e1e5beb43e740c9f850ad04401000f1ba90b5fbb Mon Sep 17 00:00:00 2001 From: daniel Date: Sun, 9 Dec 2018 22:22:17 +0100 Subject: [PATCH] Print chained exceptions when maintenance script fails. PHP supports exception chaining. This patch will output the error message and stack trace not just for the latest exceptions, but for all exceptions in the chain, using the Exception::getPrevious() method. This avoids the problem where aftereffects obscure the actual problem, because only the last exception in the chain was printed. Change-Id: If577c5c89bb3b3e5766400fff07d8cc0a2d82610 --- maintenance/doMaintenance.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/maintenance/doMaintenance.php b/maintenance/doMaintenance.php index 1f1a4c721b..816b385307 100644 --- a/maintenance/doMaintenance.php +++ b/maintenance/doMaintenance.php @@ -91,7 +91,17 @@ $maintenance->checkRequiredExtensions(); $maintenance->setAgentAndTriggers(); // Do the work -$success = $maintenance->execute(); +try { + $success = $maintenance->execute(); +} catch ( Exception $ex ) { + $success = false; + while ( $ex ) { + $cls = get_class( $ex ); + print "$cls from line {$ex->getLine()} of {$ex->getFile()}: {$ex->getMessage()}\n"; + print $ex->getTraceAsString() . "\n"; + $ex = $ex->getPrevious(); + } +} // Potentially debug globals $maintenance->globals(); -- 2.20.1