From 794c62db5869c79785ed0ae7ec05fdb9d9cb2104 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Wed, 3 Apr 2024 15:38:16 +0800 Subject: [PATCH] MDL-81419 core: Ensure that frames exist before checking them --- lib/setuplib.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/setuplib.php b/lib/setuplib.php index e95897e0723..9d3808c6050 100644 --- a/lib/setuplib.php +++ b/lib/setuplib.php @@ -385,11 +385,13 @@ function get_whoops(): ?\Whoops\Run { // Append a custom handler to add some more information to the frames. $whoops->appendHandler(function ($exception, $inspector, $run) { - // Moodle exceptions often have a link to the Moodle docs pages for them. - // Add that to the first frame in the stack. $collection = $inspector->getFrames(); - $isdebugging = str_ends_with($collection[1]->getFile(), '/lib/weblib.php'); + // Detect if the Whoops handler was immediately invoked by a call to `debugging()`. + // If so, we remove the top frames in the collection to avoid showing the inner + // workings of debugging, and the point that we trigger the error that is picked up by Whoops. + $isdebugging = count($collection) > 2; + $isdebugging = $isdebugging && str_ends_with($collection[1]->getFile(), '/lib/weblib.php'); $isdebugging = $isdebugging && $collection[2]->getFunction() === 'debugging'; if ($isdebugging) { @@ -398,6 +400,8 @@ function get_whoops(): ?\Whoops\Run { return array_search($frame, $remove) === false; }); } else { + // Moodle exceptions often have a link to the Moodle docs pages for them. + // Add that to the first frame in the stack. $info = get_exception_info($exception); if ($info->moreinfourl) { $collection[0]->addComment("{$info->moreinfourl}", 'More info');