From 915c263266d589302f858032b746501f8f770845 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Mon, 22 Dec 2025 19:45:01 +0000 Subject: [PATCH] MDL-87521 behat: better error reporting if an adhoc task fails --- public/lib/tests/behat/behat_general.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/public/lib/tests/behat/behat_general.php b/public/lib/tests/behat/behat_general.php index 8e44148804b..2c67a33668c 100644 --- a/public/lib/tests/behat/behat_general.php +++ b/public/lib/tests/behat/behat_general.php @@ -1263,7 +1263,7 @@ EOF; // Do setup for cron task. \core\cron::setup_user(); - // Discard task output as not appropriate for Behat output! + // Capture task output, in case we need it to report an error. ob_start(); // Run all tasks which have a scheduled runtime of before now. @@ -1283,11 +1283,9 @@ EOF; // If a task was successful it will be removed. // If it failed then it will still exist. if ($DB->record_exists('task_adhoc', ['id' => $task->get_id()])) { - // End ouptut buffering and flush the current buffer. - // This should be from just the current task. - ob_end_flush(); - - throw new DriverException('An adhoc task failed', 0); + // Report the error, including the task output up to the failure. + // This includes the output of any exception or other error that occurred. + throw new DriverException("An adhoc task failed. mtrace() output:\n\n" . ob_get_clean()); } } ob_end_clean();