#105897Usage of Exception getPrevious() in DataHandler may throw excpeption
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