Skip to content

Add support for catching throwables in App/Bootstrap #23350

Closed
@DuckThom

Description

@DuckThom

Summary (*)

I noticed that the inner try/catch in the run method in lib/internal/App/Bootstrap.php does not catch throwables. I was wondering if there is any downside in adding a catch for a \Throwable.

Examples (*)

If an error is thrown (for example, a TypeError) it currently shows a browser generic 500 error.

Proposed solution

I would suggest adding the following catch block for minimal changes as a quite a lot of other methods, like the catchException method for example, expect an instance of \Exception, and a TypeError isn't of that type.

catch (\Throwable $e) {
    \Magento\Framework\Profiler::stop('magento');
    $this->objectManager->get(LoggerInterface::class)->error($e->getMessage());

    // Convert the Throwable to an exception to make it compatible with catchException
    $ex = new \Exception($e->getMessage(), $e->getCode(), $e);

    if (!$application->catchException($this, $ex)) {
        throw $ex;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue: Format is validGate 1 Passed. Automatic verification of issue format passedProgress: doneTriage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject it

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions