GeezerVison is showing github.com — fix(adapter-libsql): map constraint violations from remote connections by ravitejas-tech · Pull Request #31230 · prisma/orm
Conversation
ravitejas-tech
commented
Nov 27, 2026
•
edited by coderabbitai
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
Issue: n/a, small change. CodeRabbit flagged it while reviewing #31227.
On remote libSQL connections (for example Turso over HTTP or WebSockets), @libsql/client reports errors with only the primary code string SQLITE_CONSTRAINT and no numeric rawCode. The adapter matches unique, not-null and foreign key violations on the extended code, so on remote connections they fell back to code 1, and Prisma reported P2039 instead of P2002, P2011 and P2003.
When rawCode is missing and the code is SQLITE_CONSTRAINT, the extended code is now recovered from SQLite's message (UNIQUE constraint failed, NOT NULL constraint failed, ...), so the existing mapping applies unchanged.
Where I looked
Testing
- Captured the errors that
@libsql/client 0.17.0 returns from a local sqld (ghcr.io/tursodatabase/libsql-server) over HTTP, and added unit tests with those messages. They fail without the fix.
- Ran the live
sqld errors through convertDriverError: unique and primary key violations map to UniqueConstraintViolation (with fields and table), not-null to NullConstraintViolation, and foreign key to ForeignKeyConstraintViolation.
pnpm vitest on @prisma/adapter-libsql: 32 passed.
All commits are signed off (DCO).
Summary by CodeRabbit
- Bug Fixes
- Improved reporting of remote database constraint violations, including unique, primary-key, not-null, and foreign-key errors. These errors now retain the original message.
- Other remote database errors continue to be reported as general database errors, with their original messages preserved.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Remote libSQL errors carry only the primary SQLITE_CONSTRAINT code and no
numeric rawCode, so unique, not-null and foreign key violations fell back
to code 1 and were reported as P2039. Recover the extended code from
SQLite's message when rawCode is missing, so the existing mapping applies.
Signed-off-by: Raviteja Salva <[email protected]>
coderabbitai
Bot
commented
Nov 27, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|

No actionable comments were generated in the recent review.
Walkthrough
-
The LibSQL error mapper now derives constraint codes from recognized remote SQLite error messages when numeric codes are unavailable. Tests cover unique, primary-key, not-null, foreign-key, and unrecognized errors.
Changes: LibSQL error mapping
| Layer / File(s) |
Summary |
Message-based constraint mapping packages/adapter-libsql/src/errors.ts, packages/adapter-libsql/src/errors.test.ts |
The mapper checks messages for UNIQUE, PRIMARY KEY, NOT NULL, and FOREIGN KEY constraints after numeric codes. Tests verify the mapped errors and the generic fallback for unrecognized messages. |
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix
Suggested reviewers: jacek-prisma
Merge Risk: Minimal · up to 5cbc2
-
Remote libSQL constraint violations are now reported as unique, not-null or foreign-key errors instead of the generic fallback. Numeric codes and unrecognized messages behave as before, and the new cases are covered by tests. No merge-blocking risk remains.
Pre-merge checks: 4
-
| Check name |
Status |
Explanation |
| Description Check |
 |
Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check |
 |
The title names the adapter and the change: constraint violations from remote connections are now mapped. The raw summary confirms the change derives an extended constraint code from the error message… |
| Linked Issues check |
 |
Check skipped because no linked issues were found for this pull request. |
| Out of Scope Changes check |
 |
Check skipped because no linked issues were found for this pull request. |
Full details: Title check
-
Explanation
The title names the adapter and the change: constraint violations from remote connections are now mapped. The raw summary confirms the change derives an extended constraint code from the error message when rawCode is missing for SQLITE_CONSTRAINT errors, and adds tests for unique, not-null, and foreign-key violations. The title covers the main change, though it does not mention the message-based fallback.
Finishing Touches
-
Generate unit tests (beta)
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info
-
Run configuration
-
- Source mode: Auto
- Repository: prisma/orm
- Branch: v7
- File: .coderabbit.yml
- Commit: 4c3db4a
- Layers: Repository YAML
- Review profile: ASSERTIVE
- Plan: Advanced
- Run ID:
70d7b0ce-8311-4ec0-a339-718b2a285dc2
Commits
-
Reviewing files that changed from the base of the PR and between 1cf1e2f and 5cbc24e.
Files selected for processing: 2
-
packages/adapter-libsql/src/errors.test.ts
packages/adapter-libsql/src/errors.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
… the message
SQLite appends table and column names to constraint messages, so a name
such as `UNIQUE constraint failed` could make a NOT NULL violation match
the UNIQUE entry. Strip the remote wrapper and match the header at the
start of SQLite's message instead of anywhere in it.
Signed-off-by: Raviteja Salva <[email protected]>
This branch has not been deployed
No deployments
Reviewers
At least 1 approving review is required to merge this pull request.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|