From 21b5cbe9a9573b4f3055ac38e557ba185ef0526e Mon Sep 17 00:00:00 2001 From: Rich Lott / Artful Robot Date: Thu, 24 Aug 2023 16:17:12 +0100 Subject: [PATCH] Improve browser output in case of an initialization error --- CRM/Core/Error.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/CRM/Core/Error.php b/CRM/Core/Error.php index 5e6b349e57..c9a26f8a79 100644 --- a/CRM/Core/Error.php +++ b/CRM/Core/Error.php @@ -468,8 +468,8 @@ class CRM_Core_Error extends PEAR_ErrorStack { * * @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 @@ -485,6 +485,11 @@ class CRM_Core_Error extends PEAR_ErrorStack { $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) { @@ -504,7 +509,9 @@ class CRM_Core_Error extends PEAR_ErrorStack { $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; -- 2.25.1