]> git.mjollnir.org Git - moodle.git/commitdiff
themes: MDL-19077 make sure that errors displayed by blocks are displayed properly.
authortjhunt <tjhunt>
Wed, 22 Jul 2009 02:34:24 +0000 (02:34 +0000)
committertjhunt <tjhunt>
Wed, 22 Jul 2009 02:34:24 +0000 (02:34 +0000)
Note: blocks should not be calling print_error anyway, but some did!

lib/setuplib.php

index 76445e10c699fce3a227b4798b13ea2ac5586034..28e87765f6e192b8162198559283bf8744fcf350 100644 (file)
@@ -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
 }