This commit is contained in:
Huong Nguyen
2024-03-18 09:42:06 +07:00
3 changed files with 32 additions and 7 deletions
+5
View File
@@ -790,6 +790,11 @@ $CFG->admin = 'admin';
// To further control this, the debug_developer_use_pretty_exceptions setting can be set to false.
// $CFG->debug_developer_use_pretty_exceptions = true;
//
// In many development situations it is desirable to have debugging() calls treated as errors rather than
// as exceptions.
// If this property is not specified then it will be true if pretty exceptions are usable.
// $CFG->debug_developer_debugging_as_error = true;
//
// The Whoops! UI can also provide a link to open files in your preferred editor.
// You can set your preferred editor by setting:
// $CFG->debug_developer_editor = 'vscode';
+15 -4
View File
@@ -387,10 +387,21 @@ function get_whoops(): ?\Whoops\Run {
$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.
$info = get_exception_info($exception);
if ($info->moreinfourl) {
$collection = $inspector->getFrames();
$collection[0]->addComment("{$info->moreinfourl}", 'More info');
$collection = $inspector->getFrames();
$isdebugging = str_ends_with($collection[1]->getFile(), '/lib/weblib.php');
$isdebugging = $isdebugging && $collection[2]->getFunction() === 'debugging';
if ($isdebugging) {
$remove = array_slice($collection->getArray(), 0, 2);
$collection->filter(function ($frame) use ($remove): bool {
return array_search($frame, $remove) === false;
});
} else {
$info = get_exception_info($exception);
if ($info->moreinfourl) {
$collection[0]->addComment("{$info->moreinfourl}", 'More info');
}
}
});
+12 -3
View File
@@ -3320,17 +3320,26 @@ function debugging($message = '', $level = DEBUG_NORMAL, $backtrace = null) {
// Script does not want any errors or debugging in output,
// we send the info to error log instead.
error_log('Debugging: ' . $message . ' in '. PHP_EOL . $from);
} else if ($forcedebug or $CFG->debugdisplay) {
if (!defined('DEBUGGING_PRINTED')) {
define('DEBUGGING_PRINTED', 1); // Indicates we have printed something.
}
if (CLI_SCRIPT) {
echo "++ $message ++\n$from";
} else {
echo '<div class="notifytiny debuggingmessage" data-rel="debugging">' , $message , $from , '</div>';
}
if (property_exists($CFG, 'debug_developer_debugging_as_error')) {
$showaserror = $CFG->debug_developer_debugging_as_error;
} else {
$showaserror = (bool) get_whoops();
}
if ($showaserror) {
trigger_error($message, E_USER_NOTICE);
} else {
echo '<div class="notifytiny debuggingmessage" data-rel="debugging">', $message, $from, '</div>';
}
}
} else {
trigger_error($message . $from, E_USER_NOTICE);
}