From c05e49c71a72adeb4f1fc0406292fd94e20bd03e Mon Sep 17 00:00:00 2001 From: tjhunt Date: Wed, 22 Jul 2009 02:34:24 +0000 Subject: [PATCH] themes: MDL-19077 make sure that errors displayed by blocks are displayed properly. Note: blocks should not be calling print_error anyway, but some did! --- lib/setuplib.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/setuplib.php b/lib/setuplib.php index 76445e10c6..28e87765f6 100644 --- a/lib/setuplib.php +++ b/lib/setuplib.php @@ -238,10 +238,20 @@ function print_error($errorcode, $module = 'error', $link = '', $a = null) { // Errors in unit test become exceptions, so you can unit test code that might call print_error(). if (!empty($UNITTEST->running)) { throw new moodle_exception($errorcode, $module, $link, $a); + } else { + // It is really bad if library code calls print_error when output buffering + // is on. + while (ob_get_level() > 0) { + ob_end_clean(); + } } list($message, $moreinfourl, $link) = prepare_error_message($errorcode, $module, $link, $a); - echo $OUTPUT->fatal_error($message, $moreinfourl, $link, debug_backtrace()); + if (is_stacktrace_during_output_init(debug_backtrace())) { + echo bootstrap_renderer::early_error($message, $moreinfourl, $link, debug_backtrace()); + } else { + echo $OUTPUT->fatal_error($message, $moreinfourl, $link, debug_backtrace()); + } exit(1); // General error code } -- 2.39.5