Files
turso/bindings/javascript/packages/common/sqlite-error.ts
PThorpe92 9fe63ac8f0 SDK/drivers: make parameterized batches safe and consistent
Parameterized batches could produce different effects across embedded and
serverless drivers when a later bind value was invalid. Embedded Rust also
allowed cloned connections to interleave work with a batch, and managed
batches allowed transaction-control statements to escape their wrapper.
Rollback failures were hidden, while serverless Rust could retain a stale
last-insert rowid when COMMIT failed after a successful insert.

Validate every batch input before execution, reject transaction-control SQL
before opening a managed transaction, and hold an operation-wide gate for
embedded Rust batches. Preserve both the primary and rollback errors, and
carry successful statement rowids through serverless batch decoding even
when a synthetic transaction step fails. Reject malformed serverless batch
responses instead of treating incomplete transaction steps as success.
2026-08-28 10:40:26 -07:00

26 lines
972 B
TypeScript

export class SqliteError extends Error {
name: string;
code: string;
rawCode: string;
/** For errors raised by `batch()`: the zero-based index of the failing
* statement. */
batchIndex?: number;
/** For errors raised by `batch()`: one entry per input statement, in
* order — the completed statement's `ResultSet`, or `null` for the
* failing statement and the statements that did not run. In a
* non-atomic batch the completed statements' effects are committed; in
* an atomic batch they were rolled back unless `rollbackError` is set.
* Empty when the batch failed client-side before anything was sent. */
batchResults?: Array<any | null>;
/** A rollback error that occurred while handling this error. */
rollbackError?: Error;
constructor(message, code, rawCode) {
super(message);
this.name = 'SqliteError';
this.code = code;
this.rawCode = rawCode;
(Error as any).captureStackTrace(this, SqliteError);
}
}