Error Model and Wire Error Codes
Every engine operation returns crate::error::Result<T>, an alias for Result<T, Error>. Error is one enum for the whole server. Each wire protocol translates it into its own error format at the edge. This page lists the variants and every translation table found in the code. The wire pages under Wires describe the client-visible side.
The Error enum
Error derives thiserror::Error; the Display text below is the #[error] string.
| Variant | Display text | Typical origin |
|---|---|---|
Io(std::io::Error) |
IO error: {0} |
File and socket I/O (#[from]) |
Wal(String) |
WAL error: {0} |
Write-ahead log |
SSTable(String) |
SSTable error: {0} |
SSTable read/write |
Compaction(String) |
Compaction error: {0} |
Compaction |
Corruption(String) |
Storage corrupted: {0} |
Checksum or format failure |
Transaction(String) |
Transaction error: {0} |
Generic transaction misuse, missing savepoint |
TransactionConflict(String) |
Transaction conflict: {0} |
First-committer-wins, SSI, check_serializable_row
|
TransactionAborted(String) |
Transaction aborted: {0} |
Statement in an aborted block, nested BEGIN
|
Deadlock |
deadlock detected |
Lock manager cycle |
LockTimeout |
canceling statement due to lock timeout |
Lock wait deadline |
LockNotAvailable(String) |
{0} |
NOWAIT, storage lock contention |
SavepointNotFound(String) |
Savepoint not found: {0} |
Never constructed (see below) |
TableNotFound(String) |
Table not found: {0} |
Catalog lookup |
ColumnNotFound(String) |
Column not found: {0} |
Binder |
IndexNotFound(String) |
Index not found: {0} |
Catalog lookup |
Schema(String) |
Schema error: {0} |
DDL, including "… already exists" |
Constraint(String) |
Constraint violation: {0} |
Unique, not-null, FK, check |
TypeMismatch { expected, actual } |
Type mismatch: expected {expected}, got {actual} |
Coercion |
Parse(String) |
Parse error: {0} |
SQL parser |
Semantic(String) |
Semantic error: {0} |
Planner |
QueryExecution(String) |
Query execution error: {0} |
Executor (generic) |
Unsupported(String) |
Unsupported operation: {0} |
Unimplemented feature |
InvalidArgument(String) |
Invalid argument: {0} |
Function arguments |
InvalidInput(String) |
Invalid input: {0} |
Value parsing |
Query(String) |
Query error: {0} |
Generic |
QueryTimeout(String) |
Query timeout: {0} |
statement_timeout |
DivisionByZero |
division by zero |
Arithmetic |
NumericValueOutOfRange(String) |
{0} |
Integer overflow |
StringDataRightTruncation(String) |
{0} |
Value too long for VARCHAR(n)
|
CardinalityViolation(String) |
{0} |
Scalar subquery returned more than one row |
AmbiguousColumn(String) |
{0} |
Ambiguous column reference |
GroupingError(String) |
{0} |
Column not in GROUP BY
|
Index(String) |
Index error: {0} |
Index structures |
BTree(String) |
B+Tree error: {0} |
B+tree |
VectorDimensionMismatch { expected, actual } |
Vector dimension mismatch: expected {expected}, got {actual} |
Vector operations |
Protocol(String) |
Protocol error: {0} |
Wire decoding |
AuthenticationFailed(String) |
Authentication failed: {0} |
Login |
Tls(String) |
TLS error: {0} |
TLS setup |
Connection(String) |
Connection error: {0} |
Sockets |
PermissionDenied(String) |
{0} |
Privilege checks |
Distributed(String) |
Distributed error: {0} |
Cluster |
NodeUnavailable(String) |
Node unavailable: {0} |
Cluster |
Replication(String) |
Replication error: {0} |
Replication |
ReadOnly(String) |
{0} |
Write on a Raft follower, or commit lost mid-flight |
Consensus(String) |
Consensus error: {0} |
Raft |
Serialization(String) |
Serialization error: {0} |
Encoding |
Deserialization(String) |
Deserialization error: {0} |
Decoding |
Config(String) |
Configuration error: {0} |
Configuration |
Internal(String) |
Internal error: {0} |
Invariant failure |
From conversions: std::io::Error becomes Io; bincode::Error and serde_json::Error become Serialization; toml::de::Error becomes Config. error.rs defines no wire mapping itself. (source: src/error.rs, Error, From impls)
Several variants carry the full client-facing message with no prefix (LockNotAvailable, NumericValueOutOfRange, StringDataRightTruncation, CardinalityViolation, AmbiguousColumn, GroupingError, PermissionDenied, ReadOnly), so a wire can pass Display through unchanged. On the PostgreSQL wire, pg_error_message also strips the Constraint violation: prefix so constraint errors carry PostgreSQL's own wording. (source: src/error.rs; src/protocol/postgres/mod.rs, PostgresHandler::pg_error_message)
Tested by duplicate_key_is_23505_with_pg_message in src/protocol/postgres/mod.rs tests.
Classification by message text
Constraint, Schema and QueryExecution carry one string for many conditions. Every wire mapping below distinguishes them by matching substrings of the message. A change to an engine error message can therefore change the code a client sees. (source: src/protocol/postgres/mod.rs, error_to_sqlstate; src/protocol/mysql/mod.rs, mysql_errno_for_error)
PostgreSQL SQLSTATE
PostgresHandler::error_to_sqlstate is the reference mapping. The gRPC and Arrow-style SQL paths reuse it.
| Variant (condition) | SQLSTATE |
|---|---|
TableNotFound |
42P01 |
ColumnNotFound |
42703 |
IndexNotFound |
42704 |
Schema ending " already exists", starting relation/table/index |
42P07 |
Schema ending " already exists", starting function/procedure |
42723 |
Schema ending " already exists", other |
42710 |
Schema, other |
42000 |
Constraint containing unique or duplicate |
23505 |
Constraint containing not null or null value |
23502 |
Constraint containing foreign key |
23503 |
Constraint containing check |
23514 |
Constraint, other |
23000 |
Parse |
42601 |
AmbiguousColumn |
42702 |
GroupingError |
42803 |
Semantic |
42000 |
QueryExecution schema "x" already exists
|
42P06 |
QueryExecution schema "x" does not exist, or no schema has been selected to create in
|
3F000 |
QueryExecution starting cannot drop schema
|
2BP01 |
QueryExecution starting unacceptable schema name
|
42939 |
QueryExecution containing is not yet defined in this session (currval before nextval) |
55000 |
QueryExecution prepared statement "x" does not exist
|
26000 |
QueryExecution, other |
XX000 |
QueryTimeout |
57014 |
DivisionByZero |
22012 |
NumericValueOutOfRange |
22003 |
StringDataRightTruncation |
22001 |
CardinalityViolation |
21000 |
Unsupported |
0A000 |
PermissionDenied |
42501 |
InvalidInput that pgvector classes as a data exception |
22000 |
InvalidArgument "cannot take square root of a negative number" |
2201F |
InvalidArgument, InvalidInput, other |
22023 |
TypeMismatch |
22P02 |
TransactionConflict |
40001 |
TransactionAborted |
25P02 |
Deadlock |
40P01 |
LockTimeout, LockNotAvailable
|
55P03 |
SavepointNotFound |
3B001 |
ReadOnly |
25006 |
Io, Wal, SSTable, Compaction, Corruption
|
58000 |
anything else (including Transaction, Internal, AuthenticationFailed) |
XX000 |
(source: src/protocol/postgres/mod.rs, PostgresHandler::error_to_sqlstate)
SavepointNotFound is never constructed in src/. A missing savepoint surfaces as Error::Transaction and therefore as XX000. See Savepoints. (source: src/transaction/mvcc.rs, Transaction::rollback_to_savepoint)
Tested in part by duplicate_key_is_23505_with_pg_message (23505 and 42601). Not verified: the remaining rows have no direct unit test; several are exercised indirectly by engine tests that check SQLSTATEs (for example 40001 in repeatable_read_update_of_concurrently_changed_row_is_40001).
gRPC status codes
The gRPC SQL service computes the SQLSTATE with error_to_sqlstate, maps it to a tonic status code and also sends it in the x-sqlstate metadata key.
| SQLSTATE | gRPC code |
|---|---|
| 42501 | PermissionDenied |
| 42P01, 42703, 42704, 42883, 3D000, 3F000, 26000, 25P01 | NotFound |
| 42P07, 42710, 42P06, 42723, 23505 | AlreadyExists |
| 40001, 40P01, 55P03 | Aborted |
| 57014 | DeadlineExceeded |
| 0A000 | Unimplemented |
| other 23xxx, 25xxx, 2Bxxx | FailedPrecondition |
| other 22xxx, 42xxx, 21xxx | InvalidArgument |
| anything else | Unknown |
(source: src/protocol/grpc/sql.rs, code_for_sqlstate, with_sqlstate, status_from_engine)
Tested by sqlstate_codes in src/protocol/grpc/sql.rs tests.
MySQL error numbers
The MySQL wire maps on the lowercased Display text, first match wins, then derives the SQLSTATE from the error number.
| Message contains | errno | SQLSTATE |
|---|---|---|
| deadlock, could not serialize, serialization failure, write conflict | 1213 | 40001 |
| lock timeout, lock wait timeout | 1205 | HY000 |
| table not found, no such table, table doesn't exist, unknown table | 1146 | 42S02 |
| database … already exists | 1007 | HY000 |
| already exists | 1050 | 42S01 |
| duplicate entry, duplicate key, unique constraint | 1062 | 23000 |
| unknown column, column not found | 1054 | 42S22 |
| doesn't have a default value | 1364 | 42000 |
| violates not-null constraint | 1048 | 23000 |
| violates check constraint | 3819 | HY000 |
| value too long, data too long | 1406 | 22001 |
| invalid input syntax for type integer, incorrect integer value | 1366 | HY000 |
| more than one row returned by a subquery | 1242 | 21000 |
| is ambiguous | 1052 | 23000 |
| aggregated query without group by | 1140 | 42000 |
| is not in group by clause | 1055 | 42000 |
| out of range | 1264 | 22003 |
| anything else | 1064 | 42000 |
mysql_sqlstate also knows 1210, 1243 (HY000), 1451, 1452 (23000), 1045 (28000) and 1049 (42000) for errors the handler raises directly. (source: src/protocol/mysql/mod.rs, MySqlHandler::mysql_errno_for_error, MySqlHandler::mysql_sqlstate)
A serialization failure is reported as 1213 so that MySQL clients and ORMs treat it as a retryable deadlock. Tested by check_constraint_violation_errno in src/protocol/mysql/mod.rs tests (3819). Not verified: no unit test was found for the other rows.
SQL Server (TDS) error numbers
map_engine_error returns a TsqlError. Some errors are marked .batch(), which aborts the batch.
| Variant (condition) | Number | Batch abort |
|---|---|---|
DivisionByZero |
8134 | no |
TableNotFound |
208 | yes |
ColumnNotFound |
207 | yes |
Constraint unique, duplicate or primary key |
2627 | no |
Constraint null |
515 | no |
Constraint foreign key, or other |
547 | no |
NumericValueOutOfRange |
8115 | no |
StringDataRightTruncation |
2628 | no |
CardinalityViolation |
512 | no |
PermissionDenied |
229 | no |
Deadlock, TransactionConflict
|
1205 | yes |
LockTimeout, LockNotAvailable
|
1222 | no |
TypeMismatch, InvalidInput
|
conversion error | no |
Parse |
102 | yes |
| other, by message: ambiguous 209, group by 8120, already exists 2714, conversion, divide by zero 8134, missing table 208, missing column 207, overflow 8115, too long 2628, duplicate 2627, null 515, syntax 102 | as listed | 208, 207, 102 yes |
| anything else | 50000 | no |
(source: src/protocol/mssql/tsql.rs, map_engine_error)
Not verified: no unit test of map_engine_error was found.
Oracle (TNS/TTC) error numbers
ora_error checks a few message patterns first (sequence CURRVAL not defined: ORA-08002; sequence does not exist: ORA-02289; already exists: ORA-00955; invalid number text: ORA-01722; identity column: ORA-32795), then the variant:
| Variant (condition) | ORA code |
|---|---|
PermissionDenied |
ORA-01031 |
TableNotFound |
ORA-00942 |
ColumnNotFound |
ORA-00904 |
Constraint unique, duplicate or primary key |
ORA-00001 |
Constraint not null |
ORA-01400 |
Constraint foreign key on delete or "still referenced" |
ORA-02292 |
Constraint foreign key, other |
ORA-02291 |
Constraint check |
ORA-02290 |
DivisionByZero |
ORA-01476 |
NumericValueOutOfRange |
ORA-01438 |
StringDataRightTruncation |
ORA-12899 |
CardinalityViolation |
ORA-01427 |
LockNotAvailable, LockTimeout
|
ORA-00054 |
Deadlock |
ORA-00060 |
TransactionConflict |
ORA-08177 |
TypeMismatch |
ORA-01722 |
Parse |
ORA-00900 |
Unsupported |
ORA-03001 |
| other | by message, falling back to ORA-00900 |
The fallback is never ORA-00600, because Oracle drivers treat ORA-00600 as a dead session and drop the connection. (source: src/protocol/oracle/mod.rs, ora_error)
Not verified: no unit test of ora_error was found.
ClickHouse error codes
The ClickHouse HTTP interface returns ClickHouse numeric codes:
| Variant | Code |
|---|---|
TableNotFound, IndexNotFound
|
60 (UNKNOWN_TABLE) |
ColumnNotFound |
47 (UNKNOWN_IDENTIFIER) |
Parse |
62 (SYNTAX_ERROR) |
Schema containing "already exists" |
57 (TABLE_ALREADY_EXISTS) |
Schema, other |
36 (BAD_ARGUMENTS) |
Constraint |
469 (VIOLATED_CONSTRAINT) |
QueryExecution starting "Unknown function" |
46 (UNKNOWN_FUNCTION) |
DivisionByZero |
153 (ILLEGAL_DIVISION) |
| anything else | 50 |
(source: src/protocol/clickhouse/http.rs, error_code)
Not verified: no unit test of error_code was found.
Retry guidance for client authors
The errors a client should retry are the ones produced by concurrency control:
| Condition | PostgreSQL | MySQL | SQL Server | Oracle | gRPC |
|---|---|---|---|---|---|
| Serialization failure | 40001 | 1213 | 1205 | ORA-08177 | Aborted |
| Deadlock | 40P01 | 1213 | 1205 | ORA-00060 | Aborted |
| Lock timeout / NOWAIT | 55P03 | 1205 | 1222 | ORA-00054 | Aborted |
(source: tables above)