Skip to content

Fix ConvertException false positives from SQLSTATE[HY match#1174

Closed
darkspock wants to merge 1 commit intoyiisoft:masterfrom
darkspock:fix/convert-exception-sqlstate-hy
Closed

Fix ConvertException false positives from SQLSTATE[HY match#1174
darkspock wants to merge 1 commit intoyiisoft:masterfrom
darkspock:fix/convert-exception-sqlstate-hy

Conversation

@darkspock
Copy link
Copy Markdown

Summary

ConvertException::run() matches SQLSTATE[HY in error messages to detect integrity constraint violations. However, SQLSTATE class HY is the "CLI-specific condition" class (e.g., HY000 = general error, HY001 = memory allocation error, HY010 = function sequence error). These are not integrity constraint violations and should not be wrapped as IntegrityException.

This can cause false positives where general database errors are incorrectly classified as integrity violations.

Fix

  • Remove the SQLSTATE[HY string match
  • Add a proper check using PDOException::errorInfo[0] (the SQLSTATE code) for class 23, which is the standard SQLSTATE class for integrity constraint violations across all DBMS
  • Keep the existing SQLSTATE[23 message string match and ORA-00001 match as fallbacks

Before

return match (
    str_contains($message, self::MSG_INTEGRITY_EXCEPTION_1)
    || str_contains($message, self::MGS_INTEGRITY_EXCEPTION_2)
    || str_contains($message, self::MSG_INTEGRITY_EXCEPTION_3) // SQLSTATE[HY — too broad
) {

After

$isIntegrity = str_contains($message, self::MSG_INTEGRITY_EXCEPTION_1)
    || str_contains($message, self::MGS_INTEGRITY_EXCEPTION_2)
    || $this->isIntegrityConstraintViolation($errorInfo); // checks errorInfo[0] starts with '23'

Risk

Low — this makes detection more precise. Errors that were previously (incorrectly) classified as IntegrityException will now correctly be classified as Exception. Code that catches IntegrityException specifically will no longer catch unrelated errors.

The SQLSTATE[HY string match was too broad: HY is the "CLI-specific
condition" class, not an integrity constraint class. This could cause
non-integrity errors to be incorrectly wrapped as IntegrityException.

Replace the string-based SQLSTATE[HY check with a proper errorInfo[0]
SQLSTATE code check for class 23 (integrity constraint violations),
which is the standard SQLSTATE class for these errors across all DBMS.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.71%. Comparing base (dffa745) to head (fa8d9c0).

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1174      +/-   ##
============================================
+ Coverage     98.62%   98.71%   +0.09%     
- Complexity     1645     1648       +3     
============================================
  Files           120      120              
  Lines          4292     4289       -3     
============================================
+ Hits           4233     4234       +1     
+ Misses           59       55       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Tigrov
Copy link
Copy Markdown
Member

Tigrov commented Apr 2, 2026

Another PR already fixing this part of code.
#1170

If you have any suggestions regarding this, please write comment in that PR

@vjik
Copy link
Copy Markdown
Member

vjik commented Apr 2, 2026

Closed in favor #1170

@vjik vjik closed this Apr 2, 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