Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQLite Error code example in Documentation Seems Wrong #1007

Closed
cedricvanrompay opened this issue May 8, 2023 · 1 comment · Fixed by #1009
Closed

SQLite Error code example in Documentation Seems Wrong #1007

cedricvanrompay opened this issue May 8, 2023 · 1 comment · Fixed by #1009

Comments

@cedricvanrompay
Copy link
Contributor

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.

@Prinzhorn
Copy link
Contributor

Prinzhorn commented May 11, 2023

Sounds accurate, given that the code uses sqlite3_extended_errcode

ThrowSqliteError(addon, sqlite3_errmsg(db_handle), sqlite3_extended_errcode(db_handle));

SetCode(isolate, SQLITE_OK, "SQLITE_OK");
SetCode(isolate, SQLITE_ERROR, "SQLITE_ERROR");
SetCode(isolate, SQLITE_INTERNAL, "SQLITE_INTERNAL");
SetCode(isolate, SQLITE_PERM, "SQLITE_PERM");
SetCode(isolate, SQLITE_ABORT, "SQLITE_ABORT");
SetCode(isolate, SQLITE_BUSY, "SQLITE_BUSY");
SetCode(isolate, SQLITE_LOCKED, "SQLITE_LOCKED");
SetCode(isolate, SQLITE_NOMEM, "SQLITE_NOMEM");
SetCode(isolate, SQLITE_READONLY, "SQLITE_READONLY");
SetCode(isolate, SQLITE_INTERRUPT, "SQLITE_INTERRUPT");
SetCode(isolate, SQLITE_IOERR, "SQLITE_IOERR");
SetCode(isolate, SQLITE_CORRUPT, "SQLITE_CORRUPT");
SetCode(isolate, SQLITE_NOTFOUND, "SQLITE_NOTFOUND");
SetCode(isolate, SQLITE_FULL, "SQLITE_FULL");
SetCode(isolate, SQLITE_CANTOPEN, "SQLITE_CANTOPEN");
SetCode(isolate, SQLITE_PROTOCOL, "SQLITE_PROTOCOL");
SetCode(isolate, SQLITE_EMPTY, "SQLITE_EMPTY");
SetCode(isolate, SQLITE_SCHEMA, "SQLITE_SCHEMA");
SetCode(isolate, SQLITE_TOOBIG, "SQLITE_TOOBIG");
SetCode(isolate, SQLITE_CONSTRAINT, "SQLITE_CONSTRAINT");
SetCode(isolate, SQLITE_MISMATCH, "SQLITE_MISMATCH");
SetCode(isolate, SQLITE_MISUSE, "SQLITE_MISUSE");
SetCode(isolate, SQLITE_NOLFS, "SQLITE_NOLFS");
SetCode(isolate, SQLITE_AUTH, "SQLITE_AUTH");
SetCode(isolate, SQLITE_FORMAT, "SQLITE_FORMAT");
SetCode(isolate, SQLITE_RANGE, "SQLITE_RANGE");
SetCode(isolate, SQLITE_NOTADB, "SQLITE_NOTADB");
SetCode(isolate, SQLITE_NOTICE, "SQLITE_NOTICE");
SetCode(isolate, SQLITE_WARNING, "SQLITE_WARNING");
SetCode(isolate, SQLITE_ROW, "SQLITE_ROW");
SetCode(isolate, SQLITE_DONE, "SQLITE_DONE");
SetCode(isolate, SQLITE_IOERR_READ, "SQLITE_IOERR_READ");
SetCode(isolate, SQLITE_IOERR_SHORT_READ, "SQLITE_IOERR_SHORT_READ");
SetCode(isolate, SQLITE_IOERR_WRITE, "SQLITE_IOERR_WRITE");
SetCode(isolate, SQLITE_IOERR_FSYNC, "SQLITE_IOERR_FSYNC");
SetCode(isolate, SQLITE_IOERR_DIR_FSYNC, "SQLITE_IOERR_DIR_FSYNC");
SetCode(isolate, SQLITE_IOERR_TRUNCATE, "SQLITE_IOERR_TRUNCATE");
SetCode(isolate, SQLITE_IOERR_FSTAT, "SQLITE_IOERR_FSTAT");
SetCode(isolate, SQLITE_IOERR_UNLOCK, "SQLITE_IOERR_UNLOCK");
SetCode(isolate, SQLITE_IOERR_RDLOCK, "SQLITE_IOERR_RDLOCK");
SetCode(isolate, SQLITE_IOERR_DELETE, "SQLITE_IOERR_DELETE");
SetCode(isolate, SQLITE_IOERR_BLOCKED, "SQLITE_IOERR_BLOCKED");
SetCode(isolate, SQLITE_IOERR_NOMEM, "SQLITE_IOERR_NOMEM");
SetCode(isolate, SQLITE_IOERR_ACCESS, "SQLITE_IOERR_ACCESS");
SetCode(isolate, SQLITE_IOERR_CHECKRESERVEDLOCK, "SQLITE_IOERR_CHECKRESERVEDLOCK");
SetCode(isolate, SQLITE_IOERR_LOCK, "SQLITE_IOERR_LOCK");
SetCode(isolate, SQLITE_IOERR_CLOSE, "SQLITE_IOERR_CLOSE");
SetCode(isolate, SQLITE_IOERR_DIR_CLOSE, "SQLITE_IOERR_DIR_CLOSE");
SetCode(isolate, SQLITE_IOERR_SHMOPEN, "SQLITE_IOERR_SHMOPEN");
SetCode(isolate, SQLITE_IOERR_SHMSIZE, "SQLITE_IOERR_SHMSIZE");
SetCode(isolate, SQLITE_IOERR_SHMLOCK, "SQLITE_IOERR_SHMLOCK");
SetCode(isolate, SQLITE_IOERR_SHMMAP, "SQLITE_IOERR_SHMMAP");
SetCode(isolate, SQLITE_IOERR_SEEK, "SQLITE_IOERR_SEEK");
SetCode(isolate, SQLITE_IOERR_DELETE_NOENT, "SQLITE_IOERR_DELETE_NOENT");
SetCode(isolate, SQLITE_IOERR_MMAP, "SQLITE_IOERR_MMAP");
SetCode(isolate, SQLITE_IOERR_GETTEMPPATH, "SQLITE_IOERR_GETTEMPPATH");
SetCode(isolate, SQLITE_IOERR_CONVPATH, "SQLITE_IOERR_CONVPATH");
SetCode(isolate, SQLITE_IOERR_VNODE, "SQLITE_IOERR_VNODE");
SetCode(isolate, SQLITE_IOERR_AUTH, "SQLITE_IOERR_AUTH");
SetCode(isolate, SQLITE_LOCKED_SHAREDCACHE, "SQLITE_LOCKED_SHAREDCACHE");
SetCode(isolate, SQLITE_BUSY_RECOVERY, "SQLITE_BUSY_RECOVERY");
SetCode(isolate, SQLITE_BUSY_SNAPSHOT, "SQLITE_BUSY_SNAPSHOT");
SetCode(isolate, SQLITE_CANTOPEN_NOTEMPDIR, "SQLITE_CANTOPEN_NOTEMPDIR");
SetCode(isolate, SQLITE_CANTOPEN_ISDIR, "SQLITE_CANTOPEN_ISDIR");
SetCode(isolate, SQLITE_CANTOPEN_FULLPATH, "SQLITE_CANTOPEN_FULLPATH");
SetCode(isolate, SQLITE_CANTOPEN_CONVPATH, "SQLITE_CANTOPEN_CONVPATH");
SetCode(isolate, SQLITE_CORRUPT_VTAB, "SQLITE_CORRUPT_VTAB");
SetCode(isolate, SQLITE_READONLY_RECOVERY, "SQLITE_READONLY_RECOVERY");
SetCode(isolate, SQLITE_READONLY_CANTLOCK, "SQLITE_READONLY_CANTLOCK");
SetCode(isolate, SQLITE_READONLY_ROLLBACK, "SQLITE_READONLY_ROLLBACK");
SetCode(isolate, SQLITE_READONLY_DBMOVED, "SQLITE_READONLY_DBMOVED");
SetCode(isolate, SQLITE_ABORT_ROLLBACK, "SQLITE_ABORT_ROLLBACK");
SetCode(isolate, SQLITE_CONSTRAINT_CHECK, "SQLITE_CONSTRAINT_CHECK");
SetCode(isolate, SQLITE_CONSTRAINT_COMMITHOOK, "SQLITE_CONSTRAINT_COMMITHOOK");
SetCode(isolate, SQLITE_CONSTRAINT_FOREIGNKEY, "SQLITE_CONSTRAINT_FOREIGNKEY");
SetCode(isolate, SQLITE_CONSTRAINT_FUNCTION, "SQLITE_CONSTRAINT_FUNCTION");
SetCode(isolate, SQLITE_CONSTRAINT_NOTNULL, "SQLITE_CONSTRAINT_NOTNULL");
SetCode(isolate, SQLITE_CONSTRAINT_PRIMARYKEY, "SQLITE_CONSTRAINT_PRIMARYKEY");
SetCode(isolate, SQLITE_CONSTRAINT_TRIGGER, "SQLITE_CONSTRAINT_TRIGGER");
SetCode(isolate, SQLITE_CONSTRAINT_UNIQUE, "SQLITE_CONSTRAINT_UNIQUE");
SetCode(isolate, SQLITE_CONSTRAINT_VTAB, "SQLITE_CONSTRAINT_VTAB");
SetCode(isolate, SQLITE_CONSTRAINT_ROWID, "SQLITE_CONSTRAINT_ROWID");
SetCode(isolate, SQLITE_NOTICE_RECOVER_WAL, "SQLITE_NOTICE_RECOVER_WAL");
SetCode(isolate, SQLITE_NOTICE_RECOVER_ROLLBACK, "SQLITE_NOTICE_RECOVER_ROLLBACK");
SetCode(isolate, SQLITE_WARNING_AUTOINDEX, "SQLITE_WARNING_AUTOINDEX");
SetCode(isolate, SQLITE_AUTH_USER, "SQLITE_AUTH_USER");
SetCode(isolate, SQLITE_OK_LOAD_PERMANENTLY, "SQLITE_OK_LOAD_PERMANENTLY");

I'm sure a PR updating the docs is appreciated 🎉

cedricvanrompay added a commit to cedricvanrompay/better-sqlite3 that referenced this issue May 12, 2023
m4heshd added a commit to m4heshd/better-sqlite3-multiple-ciphers that referenced this issue Sep 5, 2023
Fixes WiseLibs/better-sqlite3#1007

Co-authored-by: Cédric Van Rompay <cedric.vanrompay@gmail.com>
maplemike pushed a commit to GlobalTill/nsqlite3 that referenced this issue Jan 25, 2024
maplemike added a commit to GlobalTill/nsqlite3 that referenced this issue Jan 25, 2024
adriaticaz9 added a commit to adriaticaz9/better-sqlite3 that referenced this issue Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants