Skip to content

Handle PostgreSQL FATAL exception#473

Open
mlutonsky wants to merge 15 commits intodg:masterfrom
mlutonsky:fix-handle-pgsql-fatal-exception
Open

Handle PostgreSQL FATAL exception#473
mlutonsky wants to merge 15 commits intodg:masterfrom
mlutonsky:fix-handle-pgsql-fatal-exception

Conversation

@mlutonsky
Copy link

  • bug fix
  • BC break? no

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\Exception constructor:

dibi_pgsql
(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.

Copilot AI review requested due to automatic review settings February 17, 2026 09:36
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +135 to +136
if ($code === null && preg_match('#^(ERROR|FATAL):\s+(\S+):\s*#', $message, $m)) {
$code = $m[2];
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
dg added a commit that referenced this pull request Feb 22, 2026
dg added a commit that referenced this pull request Feb 22, 2026
dg added a commit that referenced this pull request Feb 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants