Remove try...catch from SessionHandler::write

Created on 19 July 2015, over 9 years ago
Updated 6 January 2024, 11 months ago

Problem/Motivation

Quoting from SessionHandler::write():

  public function write($sid, $value) {
    // The exception handler is not active at this point, so we need to do it
    // manually.
    try {
      [...]
      return TRUE;
    }
    catch (\Exception $exception) {
      require_once DRUPAL_ROOT . '/core/includes/errors.inc';
      // If we are displaying errors, then do so with no possibility of a
      // further uncaught exception being thrown.
      if (error_displayable()) {
        print '<h1>Uncaught exception thrown in session handler.</h1>';
        print '<p>' . Error::renderExceptionSafe($exception) . '</p><hr />';
      }
      return FALSE;
    }
  }

The comments are out of date, the exception handler is in place way before the session subsystem gets initialized. In addition it is preferable to let an exception fall through to the exception handler instead of attempting to render it into the (already finished) output because:

  1. The exception handler will try to properly log the exception
  2. The output might be of a different type than HTML

Proposed resolution

Remove the try...catch.

Remaining tasks

Review.
Decide if a BC layer is needed.

User interface changes

None.

API changes

None.

Data model changes

None.

Beta phase evaluation

<!--Uncomment the relevant rows for the issue. -->
πŸ› Bug report
Status

Fixed

Version

11.0 πŸ”₯

Component
BaseΒ  β†’

Last updated 33 minutes ago

Created by

πŸ‡¨πŸ‡­Switzerland znerol

Live updates comments and jobs are added and updated live.
  • Quick fix

    Very small and simple change. Preferred over Quickfix.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024