Files
rea/src/sqlite/SqliteDatabaseLimits.ts
T
Dery Ferdika 89fea8130a fix(sqlite): report result-column capacity refusals as capacity (#6327)
A projection wider than SQLite's native result-column limit failed with the
generic "too many columns in result set" SQL error. The inspector could not
attribute that error to a generated column, so the worker reported "format"
and the parent blamed the caller's path as invalid_format even though the
selected database was readable.

Classify the refusal from SQLite's own column limit for the private
connection, carry the selected and engine counts through the worker reply,
and project it as a capacity resource constraint. The database stays
readable, no partial rows are returned, and the recovery names the column
counts and splitting the projection across calls.
2026-10-23 23:42:20 +09:00

53 lines
1.7 KiB
TypeScript

/** Bound frozen input, retained JSON and worker allocation before parsing untrusted files. */
export const SQLITE_DATABASE_LIMITS = {
concurrentInspections: 2,
inputBytes: 256 * 1024 * 1024,
outputBytes: 16 * 1024 * 1024,
diagnosticBytes: 1024 * 1024,
} as const;
/** Internal rejection retains the failed boundary without returning partial success. */
export class SqliteInspectionFailure extends Error {
constructor(
readonly reason:
| "format"
| "selection"
| "column-selection"
| "column-evaluation"
| "column-limit"
| "unsupported"
| "unavailable"
| "output-limit"
| "memory",
message: string,
) {
super(message);
}
}
/** Selected generated cells the private connection cannot compute; the database stays readable. */
export class SqliteColumnEvaluationFailure extends SqliteInspectionFailure {
constructor(
message: string,
/** Selected or stored columns that remain readable without the failed expressions. */
readonly readableColumns: readonly string[],
) {
super("column-evaluation", message);
}
}
/** A projection above this connection's result-column capacity; the database stays readable. */
export class SqliteColumnLimitFailure extends SqliteInspectionFailure {
constructor(
message: string,
readonly selectedColumns: number,
readonly engineColumnLimit: number,
) {
super("column-limit", message);
}
}
/** SQLite's primary result code for a native node:sqlite failure, if it carries one. */
export const sqlitePrimaryResultCode = (cause: unknown): number | undefined =>
cause instanceof Error &&
"errcode" in cause &&
typeof cause.errcode === "number"
? cause.errcode & 0xff
: undefined;