Conversation
Dibi\Driver => Dibi\Drivers\Connection Dibi\ResultDriver => Dibi\Drivers\Result Dibi\Reflector => Dibi\Drivers\Engine
Prior to this change that line of code throws Deprecated ArrayIterator::__construct(): Using an object as a backing array for ArrayIterator is deprecated, as it allows violating class constraints and invariants
There was a problem hiding this comment.
Pull request overview
This pull request fixes a bug in the PostgreSQL driver where FATAL errors (typically caused by connectivity problems or server restarts) were not properly handled, causing a PHP TypeError due to an invalid parameter being passed to the exception constructor.
Changes:
- Updated the regular expression in
createException()to handle both "ERROR" and "FATAL" message prefixes - Adjusted the capture group index from
$m[1]to$m[2]to correctly extract the error code after adding the severity level capture group
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if ($code === null && preg_match('#^(ERROR|FATAL):\s+(\S+):\s*#', $message, $m)) { | ||
| $code = $m[2]; |
There was a problem hiding this comment.
The change correctly handles FATAL error messages, but there is no test coverage for this scenario. Consider adding a test case to verify that FATAL errors are properly parsed and the correct exception is thrown with the error code extracted from the message. This would prevent regression and ensure the fix works as intended.
When a PostgreSQL fatal error is encountered (typically due to connectivity problems/server restart etc.), an exception with a "FATAL" message prefix is thrown. This message prefix is currently not handled by
\Dibi\Drivers\PgSQL\Connection::createException(), causing a PHP TypeError to be thrown due to an invalid parameter type ($code) being passed to\Dibi\Exceptionconstructor:(screenshot is from dibi 5.1)
This pull request makes a targeted improvement to error handling in the PostgreSQL driver. The change updates the regular expression used to extract error codes from PostgreSQL error messages, allowing it to handle both "ERROR" and "FATAL" message prefixes.