diff --git a/core/includes/errors.inc b/core/includes/errors.inc
index b7c15b6..03594fe 100644
--- a/core/includes/errors.inc
+++ b/core/includes/errors.inc
@@ -373,12 +373,14 @@ function format_backtrace(array $backtrace) {
     else {
       $call['function'] = 'main';
     }
-    foreach ($trace['args'] as $arg) {
-      if (is_scalar($arg)) {
-        $call['args'][] = is_string($arg) ? '\'' . filter_xss($arg) . '\'' : $arg;
-      }
-      else {
-        $call['args'][] = ucfirst(gettype($arg));
+    if (isset($trace['args'])) {
+      foreach ($trace['args'] as $arg) {
+        if (is_scalar($arg)) {
+          $call['args'][] = is_string($arg) ? '\'' . filter_xss($arg) . '\'' : $arg;
+        }
+        else {
+          $call['args'][] = ucfirst(gettype($arg));
+        }
       }
     }
     $return .= $call['function'] . '(' . implode(', ', $call['args']) . ")\n";
diff --git a/core/includes/utility.inc b/core/includes/utility.inc
index a900262..023ecb0 100644
--- a/core/includes/utility.inc
+++ b/core/includes/utility.inc
@@ -34,6 +34,12 @@ function drupal_var_export($var, $prefix = '') {
  * @see rebuild.php
  */
 function drupal_rebuild() {
+  // Remove Drupal's error and exception handlers; they rely on a working
+  // service container and other subsystems and will only cause a fatal error
+  // that hides the actual error.
+  restore_error_handler();
+  restore_exception_handler();
+
   // drupal_bootstrap(DRUPAL_BOOTSTRAP_KERNEL) will build a new kernel. This
   // comes before DRUPAL_BOOTSTRAP_PAGE_CACHE.
   PhpStorageFactory::get('service_container')->deleteAll();
@@ -50,4 +56,9 @@ function drupal_rebuild() {
 
   drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
   drupal_flush_all_caches();
+
+  // Restore Drupal's error and exception handlers.
+  // @see _drupal_bootstrap_configuration()
+  set_error_handler('_drupal_error_handler');
+  set_exception_handler('_drupal_exception_handler');
 }
diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php
index 0160119..7dafc01 100644
--- a/core/lib/Drupal/Core/DrupalKernel.php
+++ b/core/lib/Drupal/Core/DrupalKernel.php
@@ -230,9 +230,12 @@ public function discoverServiceProviders() {
         $serviceProviders[$name] = new $class();
         $this->serviceProviderClasses[] = $class;
       }
-      $filename = dirname($module_filenames[$module]) . "/$module.services.yml";
-      if (file_exists($filename)) {
-        $this->serviceYamls[] = $filename;
+      // $module might have been removed from the filesystem.
+      if (isset($module_filenames[$module])) {
+        $filename = dirname($module_filenames[$module]) . "/$module.services.yml";
+        if (file_exists($filename)) {
+          $this->serviceYamls[] = $filename;
+        }
       }
     }
 
