Heine

  • drupal
  • drupal core commits
  • about
Home

Commit 206192 by dries

- Patch #329015 by Damien Tournoud: improved error handling of batch API.

--- includes/common.inc 2009/05/01 16:45:52     1.889
+++ includes/common.inc 2009/05/03 07:35:37     1.890
@@ -10,6 +10,21 @@
  */
 
 /**
+ * Error reporting level: display no errors.
+ */
+define('ERROR_REPORTING_HIDE', 0);
+
+/**
+ * Error reporting level: display errors and warnings.
+ */
+define('ERROR_REPORTING_DISPLAY_SOME', 1);
+
+/**
+ * Error reporting level: display all messages.
+ */
+define('ERROR_REPORTING_DISPLAY_ALL', 2);
+
+/**
  * Return status for saving which involved creating a new item.
  */
 define('SAVED_NEW', 1);
@@ -754,7 +769,7 @@
  *   TRUE if the error is fatal.
  */
 function _drupal_log_error($error, $fatal = FALSE) {
-  // Initialize a maintenance theme early if the boostrap was not complete.
+  // Initialize a maintenance theme if the boostrap was not complete.
   // Do it early because drupal_set_message() triggers an init_theme().
   if ($fatal && (drupal_get_bootstrap_phase() != DRUPAL_BOOTSTRAP_FULL)) {
     unset($GLOBALS['theme']);
@@ -781,34 +796,41 @@
     $number++;
   }
 
-  // Force display of error messages in update.php or if the proper error
-  // reporting level is set.
-  $error_level = variable_get('error_level', 2);
-  if ($error_level == 2 || ($error_level == 1 && $error['%type'] != 'Notice') || (defined('MAINTENANCE_MODE') && MAINTENANCE_MODE == 'update')) {
-    drupal_set_message(t('%type: %message in %function (line %line of %file).', $error), 'error');
-  }
-
   try {
     watchdog('php', '%type: %message in %function (line %line of %file).', $error, WATCHDOG_ERROR);
   }
   catch (Exception $e) {
-    $new_error = _drupal_decode_exception($e);
-    drupal_set_message(t('%type: %message in %function (line %line of %file).', $new_error), 'error');
+    // Ignore any additional watchdog exception, as that probably means
+    // that the database was not initialized correctly.
   }
 
   if ($fatal) {
-    drupal_set_header('503 Service unavailable');
-    drupal_set_title(t('Error'));
-    if (!defined('MAINTENANCE_MODE') && drupal_get_bootstrap_phase() == DRUPAL_BOOTSTRAP_FULL) {
-      // To conserve CPU and bandwidth, omit the blocks.
-      $page = drupal_get_page(t('The website encountered an unexpected error. Please try again later.'));
-      $page['#show_blocks'] = FALSE;
-      print drupal_render_page($page);
+    drupal_set_header($_SERVER['SERVER_PROTOCOL'] . ' 500 Service unavailable (with message)');
+  }
+
+  if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {
+    if ($fatal) {
+      // When called from JavaScript, simply output the error message.
+      print t('%type: %message in %function (line %line of %file).', $error);
+      exit;
     }
-    else {
+  }
+  else {
+    // Display the message if the current error reporting level allows this type
+    // of message to be displayed, and unconditionnaly in update.php.
+    $error_level = variable_get('error_level', ERROR_REPORTING_DISPLAY_ALL);
+    $display_error = $error_level == ERROR_REPORTING_DISPLAY_ALL || ($error_level == ERROR_REPORTING_DISPLAY_SOME && $error['%type'] != 'Notice');
+    if ($display_error || (defined('MAINTENANCE_MODE') && MAINTENANCE_MODE == 'update')) {
+      drupal_set_message(t('%type: %message in %function (line %line of %file).', $error), 'error');
+    }
+
+    if ($fatal) {
+      drupal_set_title(t('Error'));
+      // We fallback to a maintenance page at this point, because the page generation
+      // itself can generate errors.
       print theme('maintenance_page', t('The website encountered an unexpected error. Please try again later.'), FALSE);
+      exit;
     }
-    exit;
   }
 }
 

--- misc/drupal.js      2009/04/27 20:19:35     1.54
+++ misc/drupal.js      2009/05/03 07:35:37     1.55
@@ -296,16 +296,16 @@
  * Build an error message from ahah response.
  */
 Drupal.ahahError = function (xmlhttp, uri) {
-  if (xmlhttp.status == 200) {
+  if (xmlhttp.status == 200 || (xmlhttp.status == 500 && xmlhttp.statusText == 'Service unavailable (with message)')) {
     if ($.trim(xmlhttp.responseText)) {
-      var message = Drupal.t('An error occurred. \n@uri\n@text', { '@uri': uri, '@text': xmlhttp.responseText });
+      var message = Drupal.t("An error occurred. \nPath: @uri\nMessage: !text", { '@uri': uri, '!text': xmlhttp.responseText });
     }
     else {
-      var message = Drupal.t('An error occurred. \n@uri\n(no information available).', { '@uri': uri });
+      var message = Drupal.t("An error occurred. \nPath: @uri\n(no information available).", {'@uri': uri });
     }
   }
   else {
-    var message = Drupal.t('An HTTP error @status occurred. \n@uri', { '@uri': uri, '@status': xmlhttp.status });
+    var message = Drupal.t("An HTTP error @status occurred. \nPath: @uri", { '@uri': uri, '@status': xmlhttp.status });
   }
   return message.replace(/\n/g, '<br />');
 };

--- modules/simpletest/tests/common.test        2009/04/27 20:19:38     1.36
+++ modules/simpletest/tests/common.test        2009/05/03 07:35:37     1.37
@@ -672,21 +672,21 @@
     );
 
     // Set error reporting to collect notices.
-    variable_set('error_level', 2);
+    variable_set('error_level', ERROR_REPORTING_DISPLAY_ALL);
     $this->drupalGet('system-test/generate-warnings');
     $this->assertErrorMessage($error_notice);
     $this->assertErrorMessage($error_warning);
     $this->assertErrorMessage($error_user_notice);
 
     // Set error reporting to not collect notices.
-    variable_set('error_level', 1);
+    variable_set('error_level', ERROR_REPORTING_DISPLAY_SOME);
     $this->drupalGet('system-test/generate-warnings');
     $this->assertNoErrorMessage($error_notice);
     $this->assertErrorMessage($error_warning);
     $this->assertErrorMessage($error_user_notice);
 
     // Set error reporting to not show any errors.
-    variable_set('error_level', 0);
+    variable_set('error_level', ERROR_REPORTING_HIDE);
     $this->drupalGet('system-test/generate-warnings');
     $this->assertNoErrorMessage($error_notice);
     $this->assertNoErrorMessage($error_warning);

--- modules/system/system.admin.inc     2009/04/27 16:33:05     1.139
+++ modules/system/system.admin.inc     2009/05/03 07:35:37     1.140
@@ -1268,11 +1268,11 @@
   $form['error_level'] = array(
     '#type' => 'radios',
     '#title' => t('Display PHP messages'),
-    '#default_value' => 2,
+    '#default_value' => ERROR_REPORTING_DISPLAY_ALL,
     '#options' => array(
-      0 => t('None'),
-      1 => t('Errors and warnings'),
-      2 => t('All messages'),
+      ERROR_REPORTING_HIDE => t('None'),
+      ERROR_REPORTING_DISPLAY_SOME => t('Errors and warnings'),
+      ERROR_REPORTING_DISPLAY_ALL => t('All messages'),
     ),
   );
 

No votes yet
  • Drupal Core
  • Download patch

Recent posts

  • Menu access, a new pitfall when going back to Drupal 5
  • Drupal 6: $base_path doesn't always point to the frontpage
  • XNA SoundEffect ContentLoadException
  • A new form element in Drupal core
  • The backstabbing March-Hare

All-time popular content

  • Update UID 1 password via JS
  • Keeping an eye on Drupal core
  • Subversion on Strato V-PowerServer
  • A new form element in Drupal core
  • Access denied - Are you sure?
more

Tags

Captcha Coding Drupal FAPI IIS Let's hope it doesn't become popular Performance PHP Planet Drupal Quiz Security V-PowerServer
more tags
  • drupal
  • drupal core commits
  • about

Copyright © 2009 by Heine Deelstra. All rights reserved.