Repository navigation
feat: add try(), which returns the database's error as a value - #88
Merged
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
There was a problem hiding this comment.
ℹ️ No critical issues. One docs gap is worth closing before users reach for
.try()inside a transaction.
Reviewed changes
I reviewed the whole of the initial commit: the new .try()/.trySync() API, the error reader, the generated code lists, the type exports, the driver-matrix scenarios, the docs and the tests. tests/query-error.test.ts passes locally. Its two live tests skip here because no database is available.
.try()and.trySync()(src/index.ts): wrapsrun/runSync. It resolves to{ value }, or to{ error }whenreadQueryErrorrecognises the rejection as the database's. Every other error is rethrown unchanged, including Reylo's row-count, parameter and decode errors.- Error reader (
src/query-error.ts): reads each driver's error into oneQueryErrorshape per dialect, with the driver's error ascause. Postgres reads pg's names and postgres.js's protocol names, and takes the SQLSTATE fromerrnoon Bun.sql. MySQL readserrno/sqlState, or parses them from a PlanetScale message, and leaves out mariadb's own 45xxx errors. SQLite takes the most specific code fromcode/extendedCode/errcode/rawCode/errno, or from the message tail on D1 and Turso. - Code lists (
scripts/error-codes.ts→src/error-codes-*.ts): generated from Postgres 18, MySQL 8.4.11 and SQLite 3.53.4 sources. The Postgres and MySQL lists load lazily, and tsc'srewriteRelativeImportExtensionsrewrites those dynamic.tsimports indist/. - Types:
TryResult,QueryError<D>and the per-dialect code unions are exported, and each.sqlmodule now exportsQueryError. The mapper, its no-engine fallback andsite/scripts/capture-types.tswere all updated together. - Driver matrix: S6c and S6d check
.try()(and.trySync()on sync clients) on every job for a unique violation, a syntax error, rows, and Reylo's own row-count error. - Docs: a
.try()section under Usage, a "Database errors" section on each dialect's page, and the updated skill line.
claude-opus-5-5 | 𝕏
This was referenced Oct 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

.try()runs a query as.run()does and resolves to{ value }, or to{ error }when the database refuses the query. The result is Standard Schema's shape, soif (result.error)narrows either way..trySync()is the same on the synchronous SQLite clients.The error
code, the SQLSTATE;condition, its name;constraint,table,column,schema,detail,hint,position,where.code(ER_DUP_ENTRY),errno,sqlState;key,constraint,table,column, read from the message.code, the most specific result code the driver gives;errcode;table,columns,constraint, read from the message.causeis the driver's own error. The object is anErrornamedQueryError, so throwing it keeps a stack..run()..sqlmodule exports the type asQueryError.Code lists
scripts/error-codes.tswritessrc/error-codes-{postgres,mysql,sqlite}.tsfrom each database's own source:errcodes.txt: 251 codes.messages_to_clients.txt: 1,777 numbers, the same as the installedmysqld_error.h.sqlite3.h: 108 codes.codealso takes any string.conditionis the strict union, so compare it to have TypeScript catch a typo.Drivers
The driver matrix gains S6c and S6d, run through every job and client shape: a unique violation and a syntax error each resolve to the database's error, read into the dialect's fields; rows resolve to the value; Reylo's own row-count error rejects. On a synchronous client,
trySyncmust give the same. The new rows are merged intoRESULTS.md;compare.tsfinds no difference. Where drivers differ:errnoand writes its own stack column overcolumn.Checks
tests/run-safe.test.ts:trySyncon node:sqlite;Docs: a
.try()section under Usage, a Database errors section on each database's page, and the agent skill.