Skip to content

Commit

Permalink
Improve browser output in case of an initialization error
Browse files Browse the repository at this point in the history
  • Loading branch information
artfulrobot committed Aug 25, 2023
1 parent a07263d commit 21b5cbe
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions CRM/Core/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,8 @@ function_exists($config->fatalErrorHandler)
*
* @param string $name name of debug section
* @param mixed $variable reference to variables that we need a trace of
* @param bool $log should we log or return the output
* @param bool $html whether to generate a HTML-escaped output
* @param bool $log should we call error_log and echo a reference, or return the output
* @param bool $html whether to generate a HTML-escaped output (not relevant if $log is truthy)
* @param bool $checkPermission should we check permissions before displaying output
* useful when we die during initialization and permissioning
* subsystem is not initialized - CRM-13765
Expand All @@ -485,6 +485,11 @@ public static function debug($name, $variable = NULL, $log = TRUE, $html = TRUE,
$name = NULL;
}

if ($log) {
// We don't want html crud in our text file logs.
$html = FALSE;
}

$out = print_r($variable, TRUE);
$prefix = NULL;
if ($html) {
Expand All @@ -504,7 +509,9 @@ public static function debug($name, $variable = NULL, $log = TRUE, $html = TRUE,
$log &&
(!$checkPermission || CRM_Core_Permission::check('view debug output'))
) {
echo $out;
$unique = substr(md5(random_bytes(32)), 0, 12);
error_log("errorID:$unique\n$out");
echo "Critical error. Please see server logs for errorID:$unique";
}

return $out;
Expand Down

0 comments on commit 21b5cbe

Please sign in to comment.