Skip to content

fix(pgsql-test): expectError keeps the original error when its savepoint cleanup fails - #1926

Merged
pyramation merged 1 commit into
mainfrom
feat/pgsql-test-expect-error-cleanup
Oct 23, 2026
Merged

pyramation merged 1 commit into
mainfrom
feat/pgsql-test-expect-error-cleanup

Conversation

@pyramation

Copy link
Copy Markdown
Contributor

Summary

This is a follow-up to #1925 and addresses the review finding on the finally cleanup.

Before: PgTestClient.expectError ran ROLLBACK TO + RELEASE in an unguarded finally. If run() had ended the transaction (ROLLBACK/COMMIT) or broken the connection, the cleanup error replaced the original error. The test then failed with a bare ROLLBACK TO SAVEPOINT can only be used in transaction blocks, and the error that would have explained the failure was lost.

After: cleanup runs in its own try. If it fails, expectError throws one error that names both errors. Nothing is swallowed.

[pgsql-test] expectError: could not roll back its savepoint (25P01: ROLLBACK TO SAVEPOINT can only be used in transaction blocks);
run() failed with original failure. Did run() end the transaction or run on another client?

cause is set to the original error. If run() succeeded, cause is the cleanup error instead.

The PR also fixes a smaller bug: matchesText now resets pattern.lastIndex. Before, a /g RegExp that was reused across calls matched on the first call and missed on the second.

Regression evidence: I added 3 tests to postgres-test.expect-error.test.ts. On main they fail as follows:

✕ reuses a global RegExp across calls
✕ reports both errors when run() ends the transaction and the savepoint cannot be rolled back
    Expected pattern: /\[pgsql-test\] expectError: could not roll back its savepoint/
    Received string:  "ROLLBACK TO SAVEPOINT can only be used in transaction blocks"
✕ reports the cleanup failure when run() succeeds but ends the transaction
    Received string:  "ROLLBACK TO SAVEPOINT can only be used in transaction blocks"

With this change, all 11 tests in the suite pass.

Link to Devin session: https://app.devin.ai/sessions/fac9ca826fe6497ab29b806da19de770
Open in Devin Desktop: https://app.devin.ai/desktop/session/fac9ca826fe6497ab29b806da19de770?variant=devin
Requested by: @pyramation

…riginal error; reset lastIndex on /g matchers
@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@tenki-reviewer

tenki-reviewer Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Review complete. No issues found — approved ✅.


This PR introduces an expectError helper on PgTestClient so failing statements can be asserted with savepoint rollback built in, plus tests covering it.

Files Change
postgres/pgsql-test/src/test-client.ts Adds an expectError method to PgTestClient that wraps a query in a savepoint, expects it to fail against a pattern or error code, and always rolls back to keep the test transaction usable.
postgres/pgsql-test/__tests__/postgres-test.expect-error.test.ts New test suite exercising expectError patterns, substring matching, and error-code matching.

Reviewed commit: ce279e2

@pyramation
pyramation merged commit a8ad01e into main Oct 23, 2026
20 checks passed
@pyramation
pyramation deleted the feat/pgsql-test-expect-error-cleanup branch October 23, 2026 02:42
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.

1 participant