fix(hrana): populate rawCode on errors from remote databases - #357
Open
OsamaAnsar wants to merge 1 commit into
Open
fix(hrana): populate rawCode on errors from remote databases#357OsamaAnsar wants to merge 1 commit into
OsamaAnsar wants to merge 1 commit into
Conversation
Remote (hrana/HTTP) errors were always constructed with rawCode undefined, while local sqlite3 errors carry it. The SQL-over-HTTP protocol only sends the string error code, so derive the numeric one from it: extract the shared SQLITE_* table and mapToBaseCode into sqlite_error_codes.ts and add mapToRawCode, which resolves base and extended code names to the base numeric code and returns undefined for non-SQLite codes. Closes tursodatabase#117
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.
Closes #117.
Errors from remote databases (hrana / SQL-over-HTTP) were always constructed with
rawCode: undefined, while errors from a localsqlite3database carry it. The SQL-over-HTTP protocol only sends the string error code (proto.Erroris{ message, code }), so this derives the numeric code from the string when it is aSQLITE_*one.Changes
sqlite_error_codes.ts(new) — moves the sharedSQLITE_*code table andmapToBaseCodeout of the node-onlysqlite3.tssohrana.ts(which also runs on the web) can use them without pulling inlibsql. AddsmapToRawCode(code): resolves a base name (SQLITE_CONSTRAINT→ 19) or an extended name (SQLITE_CONSTRAINT_PRIMARYKEY→ 19) to the base numeric code, and returnsundefinedfor anything not recognised, including the client's own non-SQLite codes (HRANA_PROTO_ERROR,SERVER_ERROR, …).hrana.ts—mapHranaErrornow passesmapToRawCode(code)instead ofundefined.sqlite3.ts— imports the moved helpers; behaviour unchanged.Tests
__tests__/sqlite_error_codes.test.ts(new) — unit tests formapToBaseCode/mapToRawCode, including extended-code resolution, non-SQLite codes, and a round-trip.__tests__/client.test.ts— the constraint-error cases now assertrawCodeis defined andrawCode & 0xff === 19, which holds for both the local and remote backends.tsc --noEmitandnpm run build(CJS + ESM) pass; prettier clean.