Skip to content

Error Management Overview

ts-sql-query wraps execution and processing failures in typed errors. The most important field for callers is errorReason, whose reason value identifies the semantic category of the failure.

Database and driver failures are represented with TsSqlQueryExecutionError. When the source error exposes native metadata, the mapped reason can include:

Field Meaning
databaseErrorCode The symbolic driver/database code, such as ER_DUP_ENTRY, unique_violation, SQLITE_CONSTRAINT_UNIQUE, ORA-00001, or EREQUEST. Some drivers use wrapper codes for engine errors; for example, SQL Server through mssql commonly reports EREQUEST, while the native SQL Server error number used by the mapper is in databaseErrorNumber.
databaseErrorNumber The numeric or SQLSTATE value when the driver exposes one, such as 1062, 23505, 2067, 1, or 2627.
databaseErrorMessage The original database or driver message when available.

The native mapping pages are organized for lookup: search for the code, number, SQLSTATE, or connector message you received, then read the corresponding reason, subtype, and filled fields.

Native mapping Page
MariaDB MariaDB
MySQL MySQL
Oracle Oracle
PostgreSQL PostgreSQL
SQLite SQLite
SQL Server SQL Server

A - in a native table means that semantic row is not implemented for that database family. The rows are intentionally identical across native pages, and SQL_UNKNOWN is always last.

MySQL and MariaDB reuse numeric ranges with different meanings. Their native mapping pages interpret a bare error number only against the active database family. If a number belongs only to the other family, it is treated as an unmapped numeric error and is not listed as a native mapping for the current page. When a driver provides an explicit symbolic code, that code is preserved in databaseErrorCode even if the number is otherwise ambiguous.

Prisma is not folded into the native tables because Prisma exposes its own Pxxxx error space before the underlying database error reaches the library. Prisma mappings are handled by the Prisma query runner and should be read separately from these native database pages.

For non-database failures raised by the library itself, see Library-raised errors. For the current reason type catalog, see Error types. For TypeScript declarations useful in application code, see TypeScript types.