SqlError.ts
SqlError.ts overview
Section titled “SqlError.ts overview”Defines structured failures for SQL clients and driver integrations.
SqlError wraps the different reasons a SQL operation can fail, such as
connection, authentication, authorization, syntax, constraint, or transaction
problems. Each reason keeps the original cause, optional message and
operation metadata, and whether retrying may succeed. This module also
includes schemas, guards, a SQLite error classifier, and the
ResultLengthMismatch error used by ordered batched SQL resolvers.
Since v4.0.0
Exports Grouped by Category
Section titled “Exports Grouped by Category”- converting
- errors
- AuthenticationError (class)
- AuthorizationError (class)
- ConnectionError (class)
- ConstraintError (class)
- DeadlockError (class)
- LockTimeoutError (class)
- ResultLengthMismatch (class)
- SerializationError (class)
- SqlError (class)
- SqlErrorReason (type alias)
- SqlSyntaxError (class)
- StatementTimeoutError (class)
- UniqueViolation (class)
- UnknownError (class)
- guards
- schemas
converting
Section titled “converting”classifySqliteError
Section titled “classifySqliteError”Classifies a native SQLite error cause into a SqlErrorReason using its
code or errno, with optional message and operation metadata.
Signature
declare const classifySqliteError: (cause: unknown, { message, operation }?: SqliteClassifyOptions) => SqlErrorReasonSince v4.0.0
errors
Section titled “errors”AuthenticationError (class)
Section titled “AuthenticationError (class)”SQL error reason for authentication failures such as invalid credentials; not marked retryable.
Signature
declare class AuthenticationErrorSince v4.0.0
[ReasonTypeId] (property)
Section titled “[ReasonTypeId] (property)”Marks this value as a structured SQL error reason for runtime guards.
Signature
readonly [ReasonTypeId]: "~effect/sql/SqlError/Reason"Since v4.0.0
AuthorizationError (class)
Section titled “AuthorizationError (class)”SQL error reason for authorization or permission failures; not marked retryable.
Signature
declare class AuthorizationErrorSince v4.0.0
[ReasonTypeId] (property)
Section titled “[ReasonTypeId] (property)”Marks this value as a structured SQL error reason for runtime guards.
Signature
readonly [ReasonTypeId]: "~effect/sql/SqlError/Reason"Since v4.0.0
ConnectionError (class)
Section titled “ConnectionError (class)”SQL error reason for connection or open failures; marked retryable.
Signature
declare class ConnectionErrorSince v4.0.0
[ReasonTypeId] (property)
Section titled “[ReasonTypeId] (property)”Marks this value as a structured SQL error reason for runtime guards.
Signature
readonly [ReasonTypeId]: "~effect/sql/SqlError/Reason"Since v4.0.0
ConstraintError (class)
Section titled “ConstraintError (class)”SQL error reason for a non-unique constraint violation; not marked retryable.
Signature
declare class ConstraintErrorSince v4.0.0
[ReasonTypeId] (property)
Section titled “[ReasonTypeId] (property)”Marks this value as a structured SQL error reason for runtime guards.
Signature
readonly [ReasonTypeId]: "~effect/sql/SqlError/Reason"Since v4.0.0
DeadlockError (class)
Section titled “DeadlockError (class)”SQL error reason for a database deadlock; marked retryable.
Signature
declare class DeadlockErrorSince v4.0.0
[ReasonTypeId] (property)
Section titled “[ReasonTypeId] (property)”Marks this value as a structured SQL error reason for runtime guards.
Signature
readonly [ReasonTypeId]: "~effect/sql/SqlError/Reason"Since v4.0.0
LockTimeoutError (class)
Section titled “LockTimeoutError (class)”SQL error reason for timing out while waiting on a database lock; marked retryable.
Signature
declare class LockTimeoutErrorSince v4.0.0
[ReasonTypeId] (property)
Section titled “[ReasonTypeId] (property)”Marks this value as a structured SQL error reason for runtime guards.
Signature
readonly [ReasonTypeId]: "~effect/sql/SqlError/Reason"Since v4.0.0
ResultLengthMismatch (class)
Section titled “ResultLengthMismatch (class)”Error raised when an ordered batched SQL resolver receives a different number of result rows than requests.
Signature
declare class ResultLengthMismatchSince v4.0.0
SerializationError (class)
Section titled “SerializationError (class)”SQL error reason for a transaction serialization or isolation conflict; marked retryable.
Signature
declare class SerializationErrorSince v4.0.0
[ReasonTypeId] (property)
Section titled “[ReasonTypeId] (property)”Marks this value as a structured SQL error reason for runtime guards.
Signature
readonly [ReasonTypeId]: "~effect/sql/SqlError/Reason"Since v4.0.0
SqlError (class)
Section titled “SqlError (class)”Error wrapper for SQL failures whose message, cause, and isRetryable
values are derived from its SqlErrorReason.
Signature
declare class SqlErrorSince v4.0.0
[TypeId] (property)
Section titled “[TypeId] (property)”Marks this value as the top-level SQL error wrapper for runtime guards.
Signature
readonly [TypeId]: "~effect/sql/SqlError"Since v4.0.0
cause (property)
Section titled “cause (property)”Exposes the structured SQL reason as the JavaScript error cause.
Signature
readonly cause: ConnectionError | AuthenticationError | AuthorizationError | SqlSyntaxError | UniqueViolation | ConstraintError | DeadlockError | SerializationError | LockTimeoutError | StatementTimeoutError | UnknownErrorSince v4.0.0
SqlErrorReason (type alias)
Section titled “SqlErrorReason (type alias)”Union of structured SQL error reasons, each carrying the original cause plus optional message and operation metadata.
Signature
type SqlErrorReason = | ConnectionError | AuthenticationError | AuthorizationError | SqlSyntaxError | UniqueViolation | ConstraintError | DeadlockError | SerializationError | LockTimeoutError | StatementTimeoutError | UnknownErrorSince v4.0.0
SqlSyntaxError (class)
Section titled “SqlSyntaxError (class)”SQL error reason for invalid SQL syntax; not marked retryable.
Signature
declare class SqlSyntaxErrorSince v4.0.0
[ReasonTypeId] (property)
Section titled “[ReasonTypeId] (property)”Marks this value as a structured SQL error reason for runtime guards.
Signature
readonly [ReasonTypeId]: "~effect/sql/SqlError/Reason"Since v4.0.0
StatementTimeoutError (class)
Section titled “StatementTimeoutError (class)”SQL error reason for a statement or query timeout; marked retryable.
Signature
declare class StatementTimeoutErrorSince v4.0.0
[ReasonTypeId] (property)
Section titled “[ReasonTypeId] (property)”Marks this value as a structured SQL error reason for runtime guards.
Signature
readonly [ReasonTypeId]: "~effect/sql/SqlError/Reason"Since v4.0.0
UniqueViolation (class)
Section titled “UniqueViolation (class)”SQL error reason for a unique constraint violation, including the violated constraint identifier; not marked retryable.
Signature
declare class UniqueViolationSince v4.0.0
[ReasonTypeId] (property)
Section titled “[ReasonTypeId] (property)”Marks this value as a structured SQL error reason for runtime guards.
Signature
readonly [ReasonTypeId]: "~effect/sql/SqlError/Reason"Since v4.0.0
UnknownError (class)
Section titled “UnknownError (class)”SQL error reason for an unclassified database failure; not marked retryable.
Signature
declare class UnknownErrorSince v4.0.0
[ReasonTypeId] (property)
Section titled “[ReasonTypeId] (property)”Marks this value as a structured SQL error reason for runtime guards.
Signature
readonly [ReasonTypeId]: "~effect/sql/SqlError/Reason"Since v4.0.0
guards
Section titled “guards”isSqlError
Section titled “isSqlError”Returns true when a value is a SqlError.
Signature
declare const isSqlError: (u: unknown) => u is SqlErrorSince v4.0.0
isSqlErrorReason
Section titled “isSqlErrorReason”Returns true when a value is a SqlErrorReason.
Signature
declare const isSqlErrorReason: (u: unknown) => u is SqlErrorReasonSince v4.0.0
schemas
Section titled “schemas”SqlErrorReason
Section titled “SqlErrorReason”Schema for encoding and decoding SQL error reasons.
Signature
declare const SqlErrorReason: Schema.Union< [ typeof ConnectionError, typeof AuthenticationError, typeof AuthorizationError, typeof SqlSyntaxError, typeof UniqueViolation, typeof ConstraintError, typeof DeadlockError, typeof SerializationError, typeof LockTimeoutError, typeof StatementTimeoutError, typeof UnknownError ]>Since v4.0.0