sql.sqlite.errors
import sql.sqlite.errors
sqllifts part of this module out to its own top level; each name below is shown with the path that reaches it. Anything still spelledsql.sqlite.errors.*needsimport sql.sqlite.errors.
Turning SQLite’s result codes into the shared error classes.
SQLite reports failures as small integers. The native layer puts the
extended code in front of every message it raises, in the form [2067] UNIQUE constraint failed: t.a,
and this module reads it back out and picks the class that says the same
thing in the vocabulary every adapter shares.
Extended codes rather than primary ones, because the distinctions worth acting on live there: every constraint failure is the primary code 19, and only the extended code says whether it was a unique index, a foreign key or a NOT NULL column.
Functions
primary()
sql.sqlite.errors.primary(code: number) -> number
An extended code’s primary code, which is its low byte.
Parameters
code(number)
Returns number
class_for()
sql.sqlite.class_for(code: number) -> class
The class that best describes code.
Parameters
code(number) — An extended result code.
Returns class
split_message()
sql.sqlite.split_message(message: string) -> dict
Splits the [code] message form the native layer raises.
A message without the prefix comes back with a nil code and its text unchanged, so an error raised anywhere other than the native layer still passes through this cleanly.
Parameters
message(string)
Returns dict — { code, text }
reraise()
sql.sqlite.reraise(error, query)
Re-raises an error from the native layer as the right class.
Anything that is already a SqlError passes through untouched, so
wrapping a call that itself went through here does not bury the specific
class under a general one.
Parameters
error(Error) — The error the native layer raised.query(string|nil) — The statement that was running, for context.
Raises SqlError always.
2026, Richard Ore and Zuri contributors