Ensure exceptions thrown by event subscribers are logged

Created on 17 April 2023, over 1 year ago
Updated 2 November 2023, about 1 year ago

Problem/Motivation

This was discovered by Wim in 📌 Add functional test that proves there is reasonable UX whenever a stage event subscriber has an exception Fixed . Copying here for posterity:

th[e] stack trace [of an exception raised during batch processing] should also have been logged, to make diagnosis after the fact possible. We should assert that this indeed happened. Otherwise post-mortems in the real-world (where updates will be installed automatically, and hence no user will be present to witness the error) will become impossible.

This was discovered during form updates but we want exceptions from the event subscribers like this to be logged however they occur.

Proposed resolution

  1. In \Drupal\package_manager\StageBase::dispatch() we should log any error with the backtrace.
  2. Add test coverage in StageBaseTest for the logging
  3. After 1) we should be able to remove the logging that would now be duplicated in StageBase

    For example

    We logging at the end of the catch after

    $stage_id = parent::begin(['drupal' => $target_version], $timeout);
          $this->stage();
          $this->apply();
    

    We would no longer need to log this if the exception was a StageEventException instance because this would already be logged.

    try {
          $this->postApply();
        }
        catch (\Throwable $e) {
          $this->logger->error($e->getMessage());
        }
    

    Would also not need to be logged if it is instance of StageEventException instance

      try {
          $this->destroy();
        }
        catch (StageEventException $e) {
          $this->logger->error($e->getMessage());
        }
    

    Looking at the comment before this I think we could remove the try/catch around this all together

📌 Task
Status

Fixed

Version

3.0

Component

Code

Created by

🇺🇸United States phenaproxima Massachusetts

Live updates comments and jobs are added and updated live.
  • Usability

    Makes Drupal easier to use. Preferred over UX, D7UX, etc.

Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024