From: daniel Date: Sun, 9 Dec 2018 21:22:17 +0000 (+0100) Subject: Print chained exceptions when maintenance script fails. X-Git-Tag: 1.34.0-rc.0~1562^2 X-Git-Url: https://git.cyclocoop.org/%7B%24admin_url%7Dmembres/supprimer.php?a=commitdiff_plain;h=e1e5beb43e740c9f850ad04401000f1ba90b5fbb;p=lhc%2Fweb%2Fwiklou.git 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 --- 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();