Commit 99d219aa authored by alexpott's avatar alexpott
Browse files

Issue #2317913 by jhedstrom: Early error handling can result in fatal error...

Issue #2317913 by jhedstrom: Early error handling can result in fatal error (Call to a member function get() on a non-object)
parent b313cc6a
...@@ -199,9 +199,11 @@ function _drupal_log_error($error, $fatal = FALSE) { ...@@ -199,9 +199,11 @@ function _drupal_log_error($error, $fatal = FALSE) {
// Attempt to reduce verbosity by removing DRUPAL_ROOT from the file path // Attempt to reduce verbosity by removing DRUPAL_ROOT from the file path
// in the message. This does not happen for (false) security. // in the message. This does not happen for (false) security.
$root_length = strlen(\Drupal::root()); if (\Drupal::hasService('app.root')) {
if (substr($error['%file'], 0, $root_length) == \Drupal::root()) { $root_length = strlen(\Drupal::root());
$error['%file'] = substr($error['%file'], $root_length + 1); if (substr($error['%file'], 0, $root_length) == \Drupal::root()) {
$error['%file'] = substr($error['%file'], $root_length + 1);
}
} }
// Should not translate the string to avoid errors producing more errors. // Should not translate the string to avoid errors producing more errors.
$message = format_string('%type: !message in %function (line %line of %file).', $error); $message = format_string('%type: !message in %function (line %line of %file).', $error);
...@@ -218,7 +220,13 @@ function _drupal_log_error($error, $fatal = FALSE) { ...@@ -218,7 +220,13 @@ function _drupal_log_error($error, $fatal = FALSE) {
// Generate a backtrace containing only scalar argument values. // Generate a backtrace containing only scalar argument values.
$message .= '<pre class="backtrace">' . Error::formatBacktrace($backtrace) . '</pre>'; $message .= '<pre class="backtrace">' . Error::formatBacktrace($backtrace) . '</pre>';
} }
drupal_set_message(SafeMarkup::set($message), $class, TRUE); if (\Drupal::hasService('session_manager')) {
// Message display is dependent on sessions being available.
drupal_set_message(SafeMarkup::set($message), $class, TRUE);
}
else {
print $message;
}
} }
if ($fatal) { if ($fatal) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment