Review main Merged

86958[BUGFIX] Avoid $e->getPrevious() on doctrine exceptions

Oli Bartsch CR +2 V +2 Normal +48 −70 updated 01/31/25, 12:25

Commit message

As sorted out with #105897, using $e->getPrevious()
is a left over from much older doctrine/dbal versions.
The change applies the solution core wide to prevent
calling getMessage() on null.

Review

  • Code review CR +2 Done
    • Christian Kuhn +2
    • Oli Bartsch +1
    • Stefan Bürk +1
  • Verified V +2 Done
    • Christian Kuhn +2
    • Oli Bartsch +1
    • Stefan Bürk +1
    • core-ci +1 CI

Issues 1

Files 9

Review log 2124

  1. Oli Bartsch uploaded patch set 1 11/11/24, 19:44

  2. core-ci voted on patch set 1 V +1 11/11/24, 19:50 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/69320

  3. Garvin Hicking voted on patch set 1 CR +1 V +1 11/11/24, 20:53

  4. Benni Mack voted on patch set 1 CR +1 V +1 11/11/24, 22:13

  5. Andreas Kienast commented on patch set 1 11/12/24, 07:15

    Typo3DbBackend.php:90

    We have this code at multiple locations in this file
  6. Benjamin Franzke commented on patch set 1 CR -1 11/12/24, 07:19

    Typo3DbBackend.php:90

    Why is DBALexception message ignored at all? And why did we previously assume that it has always a parent? I guess because DBALException is supposed to wrap platform exceptions. That means I guess we either workaround a doctrine bug in here or we throw these exceptions ourselves and forgot to add a parent. I think it would be good to analyze this in detail.

    Typo3DbBackend.php:90 Reply

    ack, was about to say the same. Just posting an additional grep output: ``` git grep "getPrevious()->getMessage" typo3/sysext/backend/Classes/Form/FormDataProvider/AbstractItemProvider.php: $databaseError = $e->getPrevious()->getMessage(); typo3/sysext/core/Classes/DataHandling/DataHandler.php: $databaseErrorMessage = $e->getPrevious()->getMessage(); typo3/sysext/core/Classes/DataHandling/DataHandler.php: $databaseErrorMessage = $e->getPrevious()->getMessage(); typo3/sysext/core/Classes/DataHandling/DataHandler.php: $databaseErrorMessage = $e->getPrevious()->getMessage(); typo3/sysext/core/Classes/DataHandling/DataHandler.php: $updateErrorMessage = $e->getPrevious()->getMessage(); typo3/sysext/core/Classes/DataHandling/DataHandler.php: $insertErrorMessage = $e->getPrevious()->getMessage(); typo3/sysext/core/Classes/Database/Schema/ConnectionMigrator.php: $result[$statement] = $e->getPrevious()->getMessage(); typo3/sysext/core/Classes/Database/Schema/SchemaMigrator.php: $result[$hash] = $e->getPrevious()->getMessage(); typo3/sysext/core/Classes/Database/Schema/SchemaMigrator.php: $result[$statement] = $e->getPrevious()->getMessage(); typo3/sysext/extbase/Classes/Persistence/Generic/Storage/Typo3DbBackend.php: throw new SqlErrorException($e->getPrevious()->getMessage(), 1470230766, $e); typo3/sysext/extbase/Classes/Persistence/Generic/Storage/Typo3DbBackend.php: throw new SqlErrorException($e->getPrevious()->getMessage(), 1470230767, $e); typo3/sysext/extbase/Classes/Persistence/Generic/Storage/Typo3DbBackend.php: throw new SqlErrorException($e->getPrevious()->getMessage(), 1470230768, $e); typo3/sysext/extbase/Classes/Persistence/Generic/Storage/Typo3DbBackend.php: throw new SqlErrorException($e->getPrevious()->getMessage(), 1470230769, $e); typo3/sysext/extbase/Classes/Persistence/Generic/Storage/Typo3DbBackend.php: throw new SqlErrorException($e->getPrevious()->getMessage(), 1472074485, $e); typo3/sysext/extbase/Classes/Persistence/Generic/Storage/Typo3DbBackend.php: throw new SqlErrorException($e->getPrevious()->getMessage(), 1472064721, $e); typo3/sysext/extbase/Classes/Persistence/Generic/Storage/Typo3DbBackend.php: throw new SqlErrorException($e->getPrevious()->getMessage(), 1481281404, $e); typo3/sysext/extbase/Classes/Persistence/Generic/Storage/Typo3DbBackend.php: throw new SqlErrorException($e->getPrevious()->getMessage(), 1472064775, $e); typo3/sysext/extbase/Classes/Persistence/Generic/Storage/Typo3DbBackend.php: throw new SqlErrorException($e->getPrevious()->getMessage(), 1472074379, $e); typo3/sysext/extbase/Classes/Persistence/Generic/Storage/Typo3DbBackend.php: throw new SqlErrorException($e->getPrevious()->getMessage(), 1470231748, $e); typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php: $this->getTimeTracker()->setTSlogMessage($e->getPrevious()->getMessage()); typo3/sysext/scheduler/Classes/Task/OptimizeDatabaseTableTask.php: $e->getPrevious()->getMessage(), typo3/sysext/workspaces/Classes/Hook/DataHandlerHook.php: $sqlErrors[] = $e->getPrevious()->getMessage(); typo3/sysext/workspaces/Classes/Hook/DataHandlerHook.php: $sqlErrors[] = $e->getPrevious()->getMessage(); typo3/sysext/workspaces/Classes/Hook/DataHandlerHook.php: $dataHandler->log($table, $id, DatabaseAction::PUBLISH, 0, SystemLogErrorClassification::SYSTEM_ERROR, 'During Publishing: SQL errors happened: {reason}', -1, ['reason' => $e->getPrevious()->getMessage()]); ```
  7. Benjamin Franzke commented on patch set 1 11/12/24, 07:31

    Typo3DbBackend.php:90 Reply

    I haven't performed a test yet, but my assumption is that a `Doctrine\DBAL\Schema\Exception\TableDoesNotExist` is thrown because the table is tried to be introspected since: > 76553: [FEATURE] Introduce native JSON database field type support | https://review.typo3.org/c/Packages/TYPO3.CMS/+/76553
  8. Stefan Bürk commented on patch set 1 11/12/24, 07:37

    Typo3DbBackend.php:90 Reply

    Doctrine converts exceptions, depending on the platform (generic to concrete onces), not attaching the parent exception: ``` vendor/doctrine/dbal/src/Driver/API/*/ExceptionConverter.php (Implementation) vendor/doctrine/dbal/src/Driver/API/ExceptionConverter.php (Interface) ``` We should investigate if exception has been wrapped in old PDO driver wrapping in older versions rethrowing exceptions or if that has changed in Doctrine, but not annouced because of beeing internal implementation.
  9. Benjamin Franzke commented on patch set 1 11/12/24, 07:41

    Typo3DbBackend.php:90 Reply

    ack, and `TableDoesNotExist` is one of those cases that is not wrapped (maybe because we use API that's considered internal?) but this shows that we should harden all cases.
  10. Benjamin Franzke commented on patch set 1 11/12/24, 07:45

    Typo3DbBackend.php:90 Reply

    I think my message may be hard to understand without context: Our `insert()` wrapper calls `ensureDatabaseValueTypes()`: https://github.com/TYPO3/typo3/blob/main/typo3/sysext/core/Classes/Database/Connection.php#L191 which request a table introspection: https://github.com/TYPO3/typo3/blob/42f21d4b7e2067f9a0a48f28e1ad76141063b2c3/typo3/sysext/core/Classes/Database/Connection.php#L407 …and that fails (and is not wrapped by DBAL)
  11. Stefan Bürk commented on patch set 1 11/12/24, 07:46

    Typo3DbBackend.php:90 Reply

    An insert / plain insert query on the plain doctrine connection would also throw this exception without the parent when the table does not exists. Inserting something into a table that does not exists returns an error from the database, which is converted to `TableDoesNotExists` in general. And I'd say using insert/executeStatement alonw with a insert query is not internal by doctrine. But yes, needs a global look and hardenin. Still don't get why the "parent" exception message has been used here and in other places anyway (instead of the message of the last exception).
  12. Lina Wolf commented on patch set 1 11/20/24, 16:15

    Typo3DbBackend.php:90 Reply

    Do what exactly do we need to fix the issue? Are there changes required?
  13. Christian Kuhn commented on patch set 1 01/31/25, 10:44

    Typo3DbBackend.php:90 Reply

    i think this has been decided with #105897: ditch getPrevious() is most sane solution. i'll update the patch.
  14. Christian Kuhn uploaded patch set 2 CR +1 V +1 01/31/25, 11:04

  15. Christian Kuhn commented on patch set 1 01/31/25, 11:05

    Typo3DbBackend.php:90 Reply

    Done

    Typo3DbBackend.php:90 Reply

    Done
  16. Christian Kuhn voted on patch set 2 CR +1 V +1 01/31/25, 11:07

  17. core-ci voted on patch set 2 V -1 01/31/25, 11:10 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/73255

  18. Christian Kuhn uploaded patch set 3 CR +1 V +1 01/31/25, 11:17

  19. Christian Kuhn voted on patch set 3 CR +1 V +1 01/31/25, 11:17

  20. core-ci voted on patch set 3 V +1 01/31/25, 11:23 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/73256

  21. Stefan Bürk voted on patch set 3 CR +1 V +1 01/31/25, 11:24

  22. Oli Bartsch voted on patch set 3 CR +1 V +1 01/31/25, 11:25

  23. Christian Kuhn voted on patch set 3 CR +2 V +2 01/31/25, 12:25

  24. Christian Kuhn merged patch set 4 01/31/25, 12:25