Mercurial > hg > cmmr2012-drupal-site
comparison core/includes/errors.inc @ 4:a9cd425dd02b
Update, including to Drupal core 8.6.10
| author | Chris Cannam |
|---|---|
| date | Thu, 28 Feb 2019 13:11:55 +0000 |
| parents | c75dbcec494b |
| children |
comparison
equal
deleted
inserted
replaced
| 3:307d7a7fd348 | 4:a9cd425dd02b |
|---|---|
| 3 /** | 3 /** |
| 4 * @file | 4 * @file |
| 5 * Functions for error handling. | 5 * Functions for error handling. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 use Drupal\Component\Utility\SafeMarkup; | 8 use Drupal\Component\Render\FormattableMarkup; |
| 9 use Drupal\Component\Utility\Xss; | 9 use Drupal\Component\Utility\Xss; |
| 10 use Drupal\Core\Logger\RfcLogLevel; | 10 use Drupal\Core\Logger\RfcLogLevel; |
| 11 use Drupal\Core\Render\Markup; | 11 use Drupal\Core\Render\Markup; |
| 12 use Drupal\Core\Utility\Error; | 12 use Drupal\Core\Utility\Error; |
| 13 use Symfony\Component\HttpFoundation\Response; | 13 use Symfony\Component\HttpFoundation\Response; |
| 176 | 176 |
| 177 if (PHP_SAPI === 'cli') { | 177 if (PHP_SAPI === 'cli') { |
| 178 if ($fatal) { | 178 if ($fatal) { |
| 179 // When called from CLI, simply output a plain text message. | 179 // When called from CLI, simply output a plain text message. |
| 180 // Should not translate the string to avoid errors producing more errors. | 180 // Should not translate the string to avoid errors producing more errors. |
| 181 $response->setContent(html_entity_decode(strip_tags(SafeMarkup::format('%type: @message in %function (line %line of %file).', $error))) . "\n"); | 181 $response->setContent(html_entity_decode(strip_tags(new FormattableMarkup('%type: @message in %function (line %line of %file).', $error))) . "\n"); |
| 182 $response->send(); | 182 $response->send(); |
| 183 exit; | 183 exit; |
| 184 } | 184 } |
| 185 } | 185 } |
| 186 | 186 |
| 187 if (\Drupal::hasRequest() && \Drupal::request()->isXmlHttpRequest()) { | 187 if (\Drupal::hasRequest() && \Drupal::request()->isXmlHttpRequest()) { |
| 188 if ($fatal) { | 188 if ($fatal) { |
| 189 if (error_displayable($error)) { | 189 if (error_displayable($error)) { |
| 190 // When called from JavaScript, simply output the error message. | 190 // When called from JavaScript, simply output the error message. |
| 191 // Should not translate the string to avoid errors producing more errors. | 191 // Should not translate the string to avoid errors producing more errors. |
| 192 $response->setContent(SafeMarkup::format('%type: @message in %function (line %line of %file).', $error)); | 192 $response->setContent(new FormattableMarkup('%type: @message in %function (line %line of %file).', $error)); |
| 193 $response->send(); | 193 $response->send(); |
| 194 } | 194 } |
| 195 exit; | 195 exit; |
| 196 } | 196 } |
| 197 } | 197 } |
| 224 $error_level = _drupal_get_error_level(); | 224 $error_level = _drupal_get_error_level(); |
| 225 | 225 |
| 226 if ($error_level != ERROR_REPORTING_DISPLAY_VERBOSE) { | 226 if ($error_level != ERROR_REPORTING_DISPLAY_VERBOSE) { |
| 227 // Without verbose logging, use a simple message. | 227 // Without verbose logging, use a simple message. |
| 228 | 228 |
| 229 // We call SafeMarkup::format() directly here, rather than use t() since | 229 // We use \Drupal\Component\Render\FormattableMarkup directly here, |
| 230 // we are in the middle of error handling, and we don't want t() to | 230 // rather than use t() since we are in the middle of error handling, and |
| 231 // cause further errors. | 231 // we don't want t() to cause further errors. |
| 232 $message = SafeMarkup::format('%type: @message in %function (line %line of %file).', $error); | 232 $message = new FormattableMarkup('%type: @message in %function (line %line of %file).', $error); |
| 233 } | 233 } |
| 234 else { | 234 else { |
| 235 // With verbose logging, we will also include a backtrace. | 235 // With verbose logging, we will also include a backtrace. |
| 236 | 236 |
| 237 // First trace is the error itself, already contained in the message. | 237 // First trace is the error itself, already contained in the message. |
| 239 // message, the message doesn't contain argument values, so we output it | 239 // message, the message doesn't contain argument values, so we output it |
| 240 // once more in the backtrace. | 240 // once more in the backtrace. |
| 241 array_shift($backtrace); | 241 array_shift($backtrace); |
| 242 // Generate a backtrace containing only scalar argument values. | 242 // Generate a backtrace containing only scalar argument values. |
| 243 $error['@backtrace'] = Error::formatBacktrace($backtrace); | 243 $error['@backtrace'] = Error::formatBacktrace($backtrace); |
| 244 $message = SafeMarkup::format('%type: @message in %function (line %line of %file). <pre class="backtrace">@backtrace</pre>', $error); | 244 $message = new FormattableMarkup('%type: @message in %function (line %line of %file). <pre class="backtrace">@backtrace</pre>', $error); |
| 245 } | 245 } |
| 246 } | 246 } |
| 247 | 247 |
| 248 if ($fatal) { | 248 if ($fatal) { |
| 249 // We fallback to a maintenance page at this point, because the page generation | 249 // We fallback to a maintenance page at this point, because the page generation |
| 270 } | 270 } |
| 271 | 271 |
| 272 if ($message) { | 272 if ($message) { |
| 273 if (\Drupal::hasService('session')) { | 273 if (\Drupal::hasService('session')) { |
| 274 // Message display is dependent on sessions being available. | 274 // Message display is dependent on sessions being available. |
| 275 drupal_set_message($message, $class, TRUE); | 275 \Drupal::messenger()->addMessage($message, $class, TRUE); |
| 276 } | 276 } |
| 277 else { | 277 else { |
| 278 print $message; | 278 print $message; |
| 279 } | 279 } |
| 280 } | 280 } |
