Skip to content

SQLite Error code example in Documentation Seems Wrong #1007

@cedricvanrompay

Description

@cedricvanrompay

From

Whenever an error occurs within SQLite3, a `SqliteError` object will be thrown. `SqliteError` is a subclass of `Error`. Every `SqliteError` object has a `code` property, which is a string matching one of error codes defined [here](https://sqlite.org/rescode.html) (for example, `"SQLITE_CONSTRAINT"`).
:

Every SqliteError object has a code property, which is a string matching one of error codes defined here (for example, "SQLITE_CONSTRAINT")

Looking at https://sqlite.org/rescode.html, SQLITE_CONSTRAINT is a "Primary Result Code", but SqliteError objects seem to contain "Extended Result Codes" instead, such as SQLITE_CONSTRAINT_UNIQUE.

SqliteError: UNIQUE constraint failed: accounts.email
    at eval (/src/lib/database.ts:252:16)
    at sqliteTransaction ([...]/node_modules/better-sqlite3/lib/methods/transaction.js:65:24)
    at Module.createAccount (/src/lib/database.ts:257:7)
    [...] {
  code: 'SQLITE_CONSTRAINT_UNIQUE'
}

The documentation should probably give an extended result code as example, and should probably mention the difference, because users trying to compare the SqliteError.code with a primary result code will not get the result they expect.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions