Issue Bug Closed

#105897Usage of Exception getPrevious() in DataHandler may throw excpeption

Sybille Peters 01/07/25, 15:17 updated 12/02/25, 14:27

Description

in v12 DataHandler line 7817:

try {
    // Execute the INSERT query:
    $connection->insert($table, $fieldArray);
} catch (DBALException $e) {
    $insertErrorMessage = $e->getPrevious()->getMessage();
}

If an exception is thrown in insert and the “catch” block reached, Using the following line may cause another error / exception, where the original exception is no longer displayed:

$insertErrorMessage = $e->getPrevious()->getMessage();

Reason is the getPrevious() will not always return something.

  • original exception: Doctrine\DBAL\Types\ConversionException: “Could not convert PHP value 1736118000 to type date. Expected one of the following types: null, string, DateTime”, previous=null
  • displayed Error: Call to a member function getMessage() on null

Reproduce

Can be reproduced, if you have configured a field with type “datetime”, but the field in the database is DATE (not int) and ‘dbType’ => ‘date’ is not set, then try to create a new record in the BE.

TCA config:

'config' => [
  'type' => 'datetime',
  'format' => 'date',
  //'dbType' => 'date',
  'size' => 7,
  'default' => null,
]

SQL schema:

| date_published            | date              | YES  |     | NULL     |         

Versions

  • reproduced in v12
  • code for v14 looks similar

Screenshot

exception.png

Reviews 3

Files 1

History 413

  1. Christian Kuhn commented and changed status Under Review Resolved done 0 % 100 % <span data-processor="relativetime" data-value="2025-01-14T17:45:10+00:00" > 01/14/25, 17:45 </span>

    Applied in changeset commit:705b5bf51516821047b47ff0d4a1d643f35ed594.