Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CRM/Api4/Page/AJAX.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ private function execute(string $entity, string $action, array $params = [], $in
];
$status = $statusMap[get_class($e)] ?? 500;

$errorId = rtrim(chunk_split(CRM_Utils_String::createRandom(12, CRM_Utils_String::ALPHANUMERIC), 4, '-'), '-');
$errorId = CRM_Core_Error::createErrorId();
$logMessage = "AJAX Error ({$errorId}): {$e->getMessage()}";
$logContext = ['error_id' => $errorId, 'exception' => $e];
if ($status === 500) {
Expand Down
11 changes: 10 additions & 1 deletion CRM/Core/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ public static function debug($name, $variable = NULL, $log = TRUE, $html = TRUE,

if ($log) {
// Log the output to error_log with a unique reference.
$unique = bin2hex(random_bytes(6));
$unique = static::createErrorId();
error_log("errorID:$unique\n$out");

if (!$checkPermission) {
Expand Down Expand Up @@ -945,6 +945,15 @@ public static function createError($message, $code = 8000, $level = 'Fatal', $pa
return $error;
}

/**
* Create a random identifier for an error.
*
* @return string
*/
public static function createErrorId(): string {
return rtrim(chunk_split(CRM_Utils_String::createRandom(12, CRM_Utils_String::ALPHANUMERIC), 4, '-'), '-');
}

/**
* Set a status message in the session, then bounce back to the referrer.
*
Expand Down