Issue #3260044 by kim.pepper, andypost, daffie, mfb: Add a constant for watchdog_exception message

merge-requests/1734/merge
Alex Pott 2022-02-20 09:43:10 +00:00
parent 7ca36cfc98
commit 0415f59798
No known key found for this signature in database
GPG Key ID: BDA67E7EE836E5CE
7 changed files with 19 additions and 14 deletions

View File

@ -129,7 +129,7 @@ function watchdog_exception($type, Exception $exception, $message = NULL, $varia
// Use a default value if $message is not set.
if (empty($message)) {
$message = '%type: @message in %function (line %line of %file).';
$message = Error::DEFAULT_ERROR_MESSAGE;
}
if ($link) {

View File

@ -177,7 +177,7 @@ function _drupal_log_error($error, $fatal = FALSE) {
catch (\Exception $e) {
// We can't log, for example because the database connection is not
// available. At least try to log to PHP error log.
error_log(strtr('Failed to log error: %type: @message in %function (line %line of %file). @backtrace_string', $error));
error_log(strtr('Failed to log error: ' . Error::DEFAULT_ERROR_MESSAGE . ' @backtrace_string', $error));
}
}
@ -190,7 +190,7 @@ function _drupal_log_error($error, $fatal = FALSE) {
if ($fatal) {
// When called from CLI, simply output a plain text message.
// Should not translate the string to avoid errors producing more errors.
$response->setContent(html_entity_decode(strip_tags(new FormattableMarkup('%type: @message in %function (line %line of %file).', $error))) . "\n");
$response->setContent(html_entity_decode(strip_tags(new FormattableMarkup(Error::DEFAULT_ERROR_MESSAGE, $error))) . "\n");
$response->send();
exit(1);
}
@ -201,7 +201,7 @@ function _drupal_log_error($error, $fatal = FALSE) {
if (error_displayable($error)) {
// When called from JavaScript, simply output the error message.
// Should not translate the string to avoid errors producing more errors.
$response->setContent(new FormattableMarkup('%type: @message in %function (line %line of %file).', $error));
$response->setContent(new FormattableMarkup(Error::DEFAULT_ERROR_MESSAGE, $error));
$response->send();
}
exit;
@ -240,7 +240,7 @@ function _drupal_log_error($error, $fatal = FALSE) {
// We use \Drupal\Component\Render\FormattableMarkup directly here,
// rather than use t() since we are in the middle of error handling, and
// we don't want t() to cause further errors.
$message = new FormattableMarkup('%type: @message in %function (line %line of %file).', $error);
$message = new FormattableMarkup(Error::DEFAULT_ERROR_MESSAGE, $error);
}
else {
// With verbose logging, we will also include a backtrace.
@ -252,7 +252,7 @@ function _drupal_log_error($error, $fatal = FALSE) {
array_shift($backtrace);
// Generate a backtrace containing only scalar argument values.
$error['@backtrace'] = Error::formatBacktrace($backtrace);
$message = new FormattableMarkup('%type: @message in %function (line %line of %file). <pre class="backtrace">@backtrace</pre>', $error);
$message = new FormattableMarkup(Error::DEFAULT_ERROR_MESSAGE . ' <pre class="backtrace">@backtrace</pre>', $error);
}
}

View File

@ -179,7 +179,7 @@ function update_do_one($module, $number, $dependency_map, &$context) {
$variables = Error::decodeException($e);
unset($variables['backtrace'], $variables['exception'], $variables['severity_level']);
$ret['#abort'] = ['success' => FALSE, 'query' => t('%type: @message in %function (line %line of %file).', $variables)];
$ret['#abort'] = ['success' => FALSE, 'query' => t(Error::DEFAULT_ERROR_MESSAGE, $variables)];
}
}
@ -248,7 +248,7 @@ function update_invoke_post_update($function, &$context) {
unset($variables['backtrace'], $variables['exception']);
$ret['#abort'] = [
'success' => FALSE,
'query' => t('%type: @message in %function (line %line of %file).', $variables),
'query' => t(Error::DEFAULT_ERROR_MESSAGE, $variables),
];
}
}

View File

@ -190,7 +190,7 @@ class DefaultExceptionHtmlSubscriber extends HttpExceptionSubscriberBase {
// just log it. The DefaultExceptionSubscriber will catch the original
// exception and handle it normally.
$error = Error::decodeException($e);
$this->logger->log($error['severity_level'], '%type: @message in %function (line %line of %file).', $error);
$this->logger->log($error['severity_level'], Error::DEFAULT_ERROR_MESSAGE, $error);
}
}

View File

@ -44,7 +44,7 @@ class ExceptionLoggingSubscriber implements EventSubscriberInterface {
$error = Error::decodeException($exception);
unset($error['@backtrace_string']);
$error['@uri'] = $event->getRequest()->getRequestUri();
$this->logger->get('access denied')->warning('Path: @uri. %type: @message in %function (line %line of %file).', $error);
$this->logger->get('access denied')->warning('Path: @uri. ' . Error::DEFAULT_ERROR_MESSAGE, $error);
}
/**
@ -67,7 +67,7 @@ class ExceptionLoggingSubscriber implements EventSubscriberInterface {
public function onError(ExceptionEvent $event) {
$exception = $event->getThrowable();
$error = Error::decodeException($exception);
$this->logger->get('php')->log($error['severity_level'], '%type: @message in %function (line %line of %file).', $error);
$this->logger->get('php')->log($error['severity_level'], Error::DEFAULT_ERROR_MESSAGE, $error);
$is_critical = !$exception instanceof HttpExceptionInterface || $exception->getStatusCode() >= 500;
if ($is_critical) {

View File

@ -100,7 +100,7 @@ class FinalExceptionSubscriber implements EventSubscriberInterface {
// We use \Drupal\Component\Render\FormattableMarkup directly here,
// rather than use t() since we are in the middle of error handling, and
// we don't want t() to cause further errors.
$message = new FormattableMarkup('%type: @message in %function (line %line of %file).', $error);
$message = new FormattableMarkup(Error::DEFAULT_ERROR_MESSAGE, $error);
}
else {
// With verbose logging, we will also include a backtrace.
@ -118,7 +118,7 @@ class FinalExceptionSubscriber implements EventSubscriberInterface {
// Generate a backtrace containing only scalar argument values.
$error['@backtrace'] = Error::formatBacktrace($backtrace);
$message = new FormattableMarkup('%type: @message in %function (line %line of %file). <pre class="backtrace">@backtrace</pre>', $error);
$message = new FormattableMarkup(Error::DEFAULT_ERROR_MESSAGE . ' <pre class="backtrace">@backtrace</pre>', $error);
}
}

View File

@ -20,6 +20,11 @@ class Error {
*/
const ERROR = 3;
/**
* The the default message for logging errors.
*/
const DEFAULT_ERROR_MESSAGE = '%type: @message in %function (line %line of %file).';
/**
* An array of ignored functions.
*
@ -92,7 +97,7 @@ class Error {
// no longer function correctly (as opposed to a user-triggered error), so
// we assume that it is safe to include a verbose backtrace.
$decode['@backtrace'] = Error::formatBacktrace($backtrace);
return new FormattableMarkup('%type: @message in %function (line %line of %file). <pre class="backtrace">@backtrace</pre>', $decode);
return new FormattableMarkup(Error::DEFAULT_ERROR_MESSAGE . ' <pre class="backtrace">@backtrace</pre>', $decode);
}
/**