| 1 | import * as Data from "effect/Data"; |
| 2 | |
| 3 | /** |
| 4 | * Base error properties shared by all SQLite errors. |
| 5 | */ |
| 6 | interface SQLiteErrorProps { |
| 7 | readonly message: string; |
| 8 | readonly cause?: unknown; |
| 9 | } |
| 10 | |
| 11 | // ============================================================================= |
| 12 | // Primary Result Codes |
| 13 | // ============================================================================= |
| 14 | |
| 15 | /** |
| 16 | * SQLITE_ERROR (1) - Generic error code. |
| 17 | */ |
| 18 | export class SQLiteError extends Data.TaggedError( |
| 19 | "SQLITE_ERROR", |
| 20 | )<SQLiteErrorProps> {} |
| 21 | |
| 22 | /** |
| 23 | * SQLITE_INTERNAL (2) - Internal malfunction. |
| 24 | */ |
| 25 | export class SQLiteInternal extends Data.TaggedError( |
| 26 | "SQLITE_INTERNAL", |
| 27 | )<SQLiteErrorProps> {} |
| 28 | |
| 29 | /** |
| 30 | * SQLITE_PERM (3) - Access permission denied. |
| 31 | */ |
| 32 | export class SQLitePerm extends Data.TaggedError( |
| 33 | "SQLITE_PERM", |
| 34 | )<SQLiteErrorProps> {} |
| 35 | |
| 36 | /** |
| 37 | * SQLITE_ABORT (4) - Operation aborted. |
| 38 | */ |
| 39 | export class SQLiteAbort extends Data.TaggedError( |
| 40 | "SQLITE_ABORT", |
| 41 | )<SQLiteErrorProps> {} |
| 42 | |
| 43 | /** |
| 44 | * SQLITE_BUSY (5) - Database file is locked. |
| 45 | */ |
| 46 | export class SQLiteBusy extends Data.TaggedError( |
| 47 | "SQLITE_BUSY", |
| 48 | )<SQLiteErrorProps> {} |
| 49 | |
| 50 | /** |
| 51 | * SQLITE_LOCKED (6) - A table in the database is locked. |
| 52 | */ |
| 53 | export class SQLiteLocked extends Data.TaggedError( |
| 54 | "SQLITE_LOCKED", |
| 55 | )<SQLiteErrorProps> {} |
| 56 | |
| 57 | /** |
| 58 | * SQLITE_NOMEM (7) - Memory allocation failed. |
| 59 | */ |
| 60 | export class SQLiteNomem extends Data.TaggedError( |
| 61 | "SQLITE_NOMEM", |
| 62 | )<SQLiteErrorProps> {} |
| 63 | |
| 64 | /** |
| 65 | * SQLITE_READONLY (8) - Attempt to write a readonly database. |
| 66 | */ |
| 67 | export class SQLiteReadonly extends Data.TaggedError( |
| 68 | "SQLITE_READONLY", |
| 69 | )<SQLiteErrorProps> {} |
| 70 | |
| 71 | /** |
| 72 | * SQLITE_INTERRUPT (9) - Operation interrupted. |
| 73 | */ |
| 74 | export class SQLiteInterrupt extends Data.TaggedError( |
| 75 | "SQLITE_INTERRUPT", |
| 76 | )<SQLiteErrorProps> {} |
| 77 | |
| 78 | /** |
| 79 | * SQLITE_IOERR (10) - I/O error. |
| 80 | */ |
| 81 | export class SQLiteIoerr extends Data.TaggedError( |
| 82 | "SQLITE_IOERR", |
| 83 | )<SQLiteErrorProps> {} |
| 84 | |
| 85 | /** |
| 86 | * SQLITE_CORRUPT (11) - Database disk image is malformed. |
| 87 | */ |
| 88 | export class SQLiteCorrupt extends Data.TaggedError( |
| 89 | "SQLITE_CORRUPT", |
| 90 | )<SQLiteErrorProps> {} |
| 91 | |
| 92 | /** |
| 93 | * SQLITE_NOTFOUND (12) - Unknown opcode or table not found. |
| 94 | */ |
| 95 | export class SQLiteNotfound extends Data.TaggedError( |
| 96 | "SQLITE_NOTFOUND", |
| 97 | )<SQLiteErrorProps> {} |
| 98 | |
| 99 | /** |
| 100 | * SQLITE_FULL (13) - Database or disk is full. |
| 101 | */ |
| 102 | export class SQLiteFull extends Data.TaggedError( |
| 103 | "SQLITE_FULL", |
| 104 | )<SQLiteErrorProps> {} |
| 105 | |
| 106 | /** |
| 107 | * SQLITE_CANTOPEN (14) - Unable to open database file. |
| 108 | */ |
| 109 | export class SQLiteCantopen extends Data.TaggedError( |
| 110 | "SQLITE_CANTOPEN", |
| 111 | )<SQLiteErrorProps> {} |
| 112 | |
| 113 | /** |
| 114 | * SQLITE_PROTOCOL (15) - Database lock protocol error. |
| 115 | */ |
| 116 | export class SQLiteProtocol extends Data.TaggedError( |
| 117 | "SQLITE_PROTOCOL", |
| 118 | )<SQLiteErrorProps> {} |
| 119 | |
| 120 | /** |
| 121 | * SQLITE_EMPTY (16) - Internal use only. |
| 122 | */ |
| 123 | export class SQLiteEmpty extends Data.TaggedError( |
| 124 | "SQLITE_EMPTY", |
| 125 | )<SQLiteErrorProps> {} |
| 126 | |
| 127 | /** |
| 128 | * SQLITE_SCHEMA (17) - Database schema changed. |
| 129 | */ |
| 130 | export class SQLiteSchema extends Data.TaggedError( |
| 131 | "SQLITE_SCHEMA", |
| 132 | )<SQLiteErrorProps> {} |
| 133 | |
| 134 | /** |
| 135 | * SQLITE_TOOBIG (18) - String or BLOB exceeds size limit. |
| 136 | */ |
| 137 | export class SQLiteToobig extends Data.TaggedError( |
| 138 | "SQLITE_TOOBIG", |
| 139 | )<SQLiteErrorProps> {} |
| 140 | |
| 141 | /** |
| 142 | * SQLITE_CONSTRAINT (19) - Constraint violation. |
| 143 | */ |
| 144 | export class SQLiteConstraint extends Data.TaggedError( |
| 145 | "SQLITE_CONSTRAINT", |
| 146 | )<SQLiteErrorProps> {} |
| 147 | |
| 148 | /** |
| 149 | * SQLITE_MISMATCH (20) - Data type mismatch. |
| 150 | */ |
| 151 | export class SQLiteMismatch extends Data.TaggedError( |
| 152 | "SQLITE_MISMATCH", |
| 153 | )<SQLiteErrorProps> {} |
| 154 | |
| 155 | /** |
| 156 | * SQLITE_MISUSE (21) - Library used incorrectly. |
| 157 | */ |
| 158 | export class SQLiteMisuse extends Data.TaggedError( |
| 159 | "SQLITE_MISUSE", |
| 160 | )<SQLiteErrorProps> {} |
| 161 | |
| 162 | /** |
| 163 | * SQLITE_NOLFS (22) - Uses OS features not supported on host. |
| 164 | */ |
| 165 | export class SQLiteNolfs extends Data.TaggedError( |
| 166 | "SQLITE_NOLFS", |
| 167 | )<SQLiteErrorProps> {} |
| 168 | |
| 169 | /** |
| 170 | * SQLITE_AUTH (23) - Authorization denied. |
| 171 | */ |
| 172 | export class SQLiteAuth extends Data.TaggedError( |
| 173 | "SQLITE_AUTH", |
| 174 | )<SQLiteErrorProps> {} |
| 175 | |
| 176 | /** |
| 177 | * SQLITE_FORMAT (24) - Not used. |
| 178 | */ |
| 179 | export class SQLiteFormat extends Data.TaggedError( |
| 180 | "SQLITE_FORMAT", |
| 181 | )<SQLiteErrorProps> {} |
| 182 | |
| 183 | /** |
| 184 | * SQLITE_RANGE (25) - 2nd parameter to sqlite3_bind out of range. |
| 185 | */ |
| 186 | export class SQLiteRange extends Data.TaggedError( |
| 187 | "SQLITE_RANGE", |
| 188 | )<SQLiteErrorProps> {} |
| 189 | |
| 190 | /** |
| 191 | * SQLITE_NOTADB (26) - File opened that is not a database file. |
| 192 | */ |
| 193 | export class SQLiteNotadb extends Data.TaggedError( |
| 194 | "SQLITE_NOTADB", |
| 195 | )<SQLiteErrorProps> {} |
| 196 | |
| 197 | /** |
| 198 | * SQLITE_NOTICE (27) - Notifications from sqlite3_log(). |
| 199 | */ |
| 200 | export class SQLiteNotice extends Data.TaggedError( |
| 201 | "SQLITE_NOTICE", |
| 202 | )<SQLiteErrorProps> {} |
| 203 | |
| 204 | /** |
| 205 | * SQLITE_WARNING (28) - Warnings from sqlite3_log(). |
| 206 | */ |
| 207 | export class SQLiteWarning extends Data.TaggedError( |
| 208 | "SQLITE_WARNING", |
| 209 | )<SQLiteErrorProps> {} |
| 210 | |
| 211 | // ============================================================================= |
| 212 | // Extended Result Codes - ABORT |
| 213 | // ============================================================================= |
| 214 | |
| 215 | export class SQLiteAbortRollback extends Data.TaggedError( |
| 216 | "SQLITE_ABORT_ROLLBACK", |
| 217 | )<SQLiteErrorProps> {} |
| 218 | |
| 219 | // ============================================================================= |
| 220 | // Extended Result Codes - AUTH |
| 221 | // ============================================================================= |
| 222 | |
| 223 | export class SQLiteAuthUser extends Data.TaggedError( |
| 224 | "SQLITE_AUTH_USER", |
| 225 | )<SQLiteErrorProps> {} |
| 226 | |
| 227 | // ============================================================================= |
| 228 | // Extended Result Codes - BUSY |
| 229 | // ============================================================================= |
| 230 | |
| 231 | export class SQLiteBusyRecovery extends Data.TaggedError( |
| 232 | "SQLITE_BUSY_RECOVERY", |
| 233 | )<SQLiteErrorProps> {} |
| 234 | export class SQLiteBusySnapshot extends Data.TaggedError( |
| 235 | "SQLITE_BUSY_SNAPSHOT", |
| 236 | )<SQLiteErrorProps> {} |
| 237 | export class SQLiteBusyTimeout extends Data.TaggedError( |
| 238 | "SQLITE_BUSY_TIMEOUT", |
| 239 | )<SQLiteErrorProps> {} |
| 240 | |
| 241 | // ============================================================================= |
| 242 | // Extended Result Codes - CANTOPEN |
| 243 | // ============================================================================= |
| 244 | |
| 245 | export class SQLiteCantopenConvpath extends Data.TaggedError( |
| 246 | "SQLITE_CANTOPEN_CONVPATH", |
| 247 | )<SQLiteErrorProps> {} |
| 248 | export class SQLiteCantopenDirtywal extends Data.TaggedError( |
| 249 | "SQLITE_CANTOPEN_DIRTYWAL", |
| 250 | )<SQLiteErrorProps> {} |
| 251 | export class SQLiteCantopenFullpath extends Data.TaggedError( |
| 252 | "SQLITE_CANTOPEN_FULLPATH", |
| 253 | )<SQLiteErrorProps> {} |
| 254 | export class SQLiteCantopenIsdir extends Data.TaggedError( |
| 255 | "SQLITE_CANTOPEN_ISDIR", |
| 256 | )<SQLiteErrorProps> {} |
| 257 | export class SQLiteCantopenNotempdir extends Data.TaggedError( |
| 258 | "SQLITE_CANTOPEN_NOTEMPDIR", |
| 259 | )<SQLiteErrorProps> {} |
| 260 | export class SQLiteCantopenSymlink extends Data.TaggedError( |
| 261 | "SQLITE_CANTOPEN_SYMLINK", |
| 262 | )<SQLiteErrorProps> {} |
| 263 | |
| 264 | // ============================================================================= |
| 265 | // Extended Result Codes - CONSTRAINT |
| 266 | // ============================================================================= |
| 267 | |
| 268 | export class SQLiteConstraintCheck extends Data.TaggedError( |
| 269 | "SQLITE_CONSTRAINT_CHECK", |
| 270 | )<SQLiteErrorProps> {} |
| 271 | export class SQLiteConstraintCommithook extends Data.TaggedError( |
| 272 | "SQLITE_CONSTRAINT_COMMITHOOK", |
| 273 | )<SQLiteErrorProps> {} |
| 274 | export class SQLiteConstraintDatatype extends Data.TaggedError( |
| 275 | "SQLITE_CONSTRAINT_DATATYPE", |
| 276 | )<SQLiteErrorProps> {} |
| 277 | export class SQLiteConstraintForeignkey extends Data.TaggedError( |
| 278 | "SQLITE_CONSTRAINT_FOREIGNKEY", |
| 279 | )<SQLiteErrorProps> {} |
| 280 | export class SQLiteConstraintFunction extends Data.TaggedError( |
| 281 | "SQLITE_CONSTRAINT_FUNCTION", |
| 282 | )<SQLiteErrorProps> {} |
| 283 | export class SQLiteConstraintNotnull extends Data.TaggedError( |
| 284 | "SQLITE_CONSTRAINT_NOTNULL", |
| 285 | )<SQLiteErrorProps> {} |
| 286 | export class SQLiteConstraintPinned extends Data.TaggedError( |
| 287 | "SQLITE_CONSTRAINT_PINNED", |
| 288 | )<SQLiteErrorProps> {} |
| 289 | export class SQLiteConstraintPrimarykey extends Data.TaggedError( |
| 290 | "SQLITE_CONSTRAINT_PRIMARYKEY", |
| 291 | )<SQLiteErrorProps> {} |
| 292 | export class SQLiteConstraintRowid extends Data.TaggedError( |
| 293 | "SQLITE_CONSTRAINT_ROWID", |
| 294 | )<SQLiteErrorProps> {} |
| 295 | export class SQLiteConstraintTrigger extends Data.TaggedError( |
| 296 | "SQLITE_CONSTRAINT_TRIGGER", |
| 297 | )<SQLiteErrorProps> {} |
| 298 | export class SQLiteConstraintUnique extends Data.TaggedError( |
| 299 | "SQLITE_CONSTRAINT_UNIQUE", |
| 300 | )<SQLiteErrorProps> {} |
| 301 | export class SQLiteConstraintVtab extends Data.TaggedError( |
| 302 | "SQLITE_CONSTRAINT_VTAB", |
| 303 | )<SQLiteErrorProps> {} |
| 304 | |
| 305 | // ============================================================================= |
| 306 | // Extended Result Codes - CORRUPT |
| 307 | // ============================================================================= |
| 308 | |
| 309 | export class SQLiteCorruptIndex extends Data.TaggedError( |
| 310 | "SQLITE_CORRUPT_INDEX", |
| 311 | )<SQLiteErrorProps> {} |
| 312 | export class SQLiteCorruptSequence extends Data.TaggedError( |
| 313 | "SQLITE_CORRUPT_SEQUENCE", |
| 314 | )<SQLiteErrorProps> {} |
| 315 | export class SQLiteCorruptVtab extends Data.TaggedError( |
| 316 | "SQLITE_CORRUPT_VTAB", |
| 317 | )<SQLiteErrorProps> {} |
| 318 | |
| 319 | // ============================================================================= |
| 320 | // Extended Result Codes - ERROR |
| 321 | // ============================================================================= |
| 322 | |
| 323 | export class SQLiteErrorMissingCollseq extends Data.TaggedError( |
| 324 | "SQLITE_ERROR_MISSING_COLLSEQ", |
| 325 | )<SQLiteErrorProps> {} |
| 326 | export class SQLiteErrorRetry extends Data.TaggedError( |
| 327 | "SQLITE_ERROR_RETRY", |
| 328 | )<SQLiteErrorProps> {} |
| 329 | export class SQLiteErrorSnapshot extends Data.TaggedError( |
| 330 | "SQLITE_ERROR_SNAPSHOT", |
| 331 | )<SQLiteErrorProps> {} |
| 332 | |
| 333 | // ============================================================================= |
| 334 | // Extended Result Codes - IOERR |
| 335 | // ============================================================================= |
| 336 | |
| 337 | export class SQLiteIoerrAccess extends Data.TaggedError( |
| 338 | "SQLITE_IOERR_ACCESS", |
| 339 | )<SQLiteErrorProps> {} |
| 340 | export class SQLiteIoerrAuth extends Data.TaggedError( |
| 341 | "SQLITE_IOERR_AUTH", |
| 342 | )<SQLiteErrorProps> {} |
| 343 | export class SQLiteIoerrBeginAtomic extends Data.TaggedError( |
| 344 | "SQLITE_IOERR_BEGIN_ATOMIC", |
| 345 | )<SQLiteErrorProps> {} |
| 346 | export class SQLiteIoerrBlocked extends Data.TaggedError( |
| 347 | "SQLITE_IOERR_BLOCKED", |
| 348 | )<SQLiteErrorProps> {} |
| 349 | export class SQLiteIoerrCheckreservedlock extends Data.TaggedError( |
| 350 | "SQLITE_IOERR_CHECKRESERVEDLOCK", |
| 351 | )<SQLiteErrorProps> {} |
| 352 | export class SQLiteIoerrClose extends Data.TaggedError( |
| 353 | "SQLITE_IOERR_CLOSE", |
| 354 | )<SQLiteErrorProps> {} |
| 355 | export class SQLiteIoerrCommitAtomic extends Data.TaggedError( |
| 356 | "SQLITE_IOERR_COMMIT_ATOMIC", |
| 357 | )<SQLiteErrorProps> {} |
| 358 | export class SQLiteIoerrConvpath extends Data.TaggedError( |
| 359 | "SQLITE_IOERR_CONVPATH", |
| 360 | )<SQLiteErrorProps> {} |
| 361 | export class SQLiteIoerrCorruptfs extends Data.TaggedError( |
| 362 | "SQLITE_IOERR_CORRUPTFS", |
| 363 | )<SQLiteErrorProps> {} |
| 364 | export class SQLiteIoerrData extends Data.TaggedError( |
| 365 | "SQLITE_IOERR_DATA", |
| 366 | )<SQLiteErrorProps> {} |
| 367 | export class SQLiteIoerrDelete extends Data.TaggedError( |
| 368 | "SQLITE_IOERR_DELETE", |
| 369 | )<SQLiteErrorProps> {} |
| 370 | export class SQLiteIoerrDeleteNoent extends Data.TaggedError( |
| 371 | "SQLITE_IOERR_DELETE_NOENT", |
| 372 | )<SQLiteErrorProps> {} |
| 373 | export class SQLiteIoerrDirClose extends Data.TaggedError( |
| 374 | "SQLITE_IOERR_DIR_CLOSE", |
| 375 | )<SQLiteErrorProps> {} |
| 376 | export class SQLiteIoerrDirFsync extends Data.TaggedError( |
| 377 | "SQLITE_IOERR_DIR_FSYNC", |
| 378 | )<SQLiteErrorProps> {} |
| 379 | export class SQLiteIoerrFstat extends Data.TaggedError( |
| 380 | "SQLITE_IOERR_FSTAT", |
| 381 | )<SQLiteErrorProps> {} |
| 382 | export class SQLiteIoerrFsync extends Data.TaggedError( |
| 383 | "SQLITE_IOERR_FSYNC", |
| 384 | )<SQLiteErrorProps> {} |
| 385 | export class SQLiteIoerrGettemppath extends Data.TaggedError( |
| 386 | "SQLITE_IOERR_GETTEMPPATH", |
| 387 | )<SQLiteErrorProps> {} |
| 388 | export class SQLiteIoerrLock extends Data.TaggedError( |
| 389 | "SQLITE_IOERR_LOCK", |
| 390 | )<SQLiteErrorProps> {} |
| 391 | export class SQLiteIoerrMmap extends Data.TaggedError( |
| 392 | "SQLITE_IOERR_MMAP", |
| 393 | )<SQLiteErrorProps> {} |
| 394 | export class SQLiteIoerrNomem extends Data.TaggedError( |
| 395 | "SQLITE_IOERR_NOMEM", |
| 396 | )<SQLiteErrorProps> {} |
| 397 | export class SQLiteIoerrRdlock extends Data.TaggedError( |
| 398 | "SQLITE_IOERR_RDLOCK", |
| 399 | )<SQLiteErrorProps> {} |
| 400 | export class SQLiteIoerrRead extends Data.TaggedError( |
| 401 | "SQLITE_IOERR_READ", |
| 402 | )<SQLiteErrorProps> {} |
| 403 | export class SQLiteIoerrRollbackAtomic extends Data.TaggedError( |
| 404 | "SQLITE_IOERR_ROLLBACK_ATOMIC", |
| 405 | )<SQLiteErrorProps> {} |
| 406 | export class SQLiteIoerrSeek extends Data.TaggedError( |
| 407 | "SQLITE_IOERR_SEEK", |
| 408 | )<SQLiteErrorProps> {} |
| 409 | export class SQLiteIoerrShmlock extends Data.TaggedError( |
| 410 | "SQLITE_IOERR_SHMLOCK", |
| 411 | )<SQLiteErrorProps> {} |
| 412 | export class SQLiteIoerrShmmap extends Data.TaggedError( |
| 413 | "SQLITE_IOERR_SHMMAP", |
| 414 | )<SQLiteErrorProps> {} |
| 415 | export class SQLiteIoerrShmopen extends Data.TaggedError( |
| 416 | "SQLITE_IOERR_SHMOPEN", |
| 417 | )<SQLiteErrorProps> {} |
| 418 | export class SQLiteIoerrShmsize extends Data.TaggedError( |
| 419 | "SQLITE_IOERR_SHMSIZE", |
| 420 | )<SQLiteErrorProps> {} |
| 421 | export class SQLiteIoerrShortRead extends Data.TaggedError( |
| 422 | "SQLITE_IOERR_SHORT_READ", |
| 423 | )<SQLiteErrorProps> {} |
| 424 | export class SQLiteIoerrTruncate extends Data.TaggedError( |
| 425 | "SQLITE_IOERR_TRUNCATE", |
| 426 | )<SQLiteErrorProps> {} |
| 427 | export class SQLiteIoerrUnlock extends Data.TaggedError( |
| 428 | "SQLITE_IOERR_UNLOCK", |
| 429 | )<SQLiteErrorProps> {} |
| 430 | export class SQLiteIoerrVnode extends Data.TaggedError( |
| 431 | "SQLITE_IOERR_VNODE", |
| 432 | )<SQLiteErrorProps> {} |
| 433 | export class SQLiteIoerrWrite extends Data.TaggedError( |
| 434 | "SQLITE_IOERR_WRITE", |
| 435 | )<SQLiteErrorProps> {} |
| 436 | |
| 437 | // ============================================================================= |
| 438 | // Extended Result Codes - LOCKED |
| 439 | // ============================================================================= |
| 440 | |
| 441 | export class SQLiteLockedSharedcache extends Data.TaggedError( |
| 442 | "SQLITE_LOCKED_SHAREDCACHE", |
| 443 | )<SQLiteErrorProps> {} |
| 444 | export class SQLiteLockedVtab extends Data.TaggedError( |
| 445 | "SQLITE_LOCKED_VTAB", |
| 446 | )<SQLiteErrorProps> {} |
| 447 | |
| 448 | // ============================================================================= |
| 449 | // Extended Result Codes - NOTICE |
| 450 | // ============================================================================= |
| 451 | |
| 452 | export class SQLiteNoticeRecoverRollback extends Data.TaggedError( |
| 453 | "SQLITE_NOTICE_RECOVER_ROLLBACK", |
| 454 | )<SQLiteErrorProps> {} |
| 455 | export class SQLiteNoticeRecoverWal extends Data.TaggedError( |
| 456 | "SQLITE_NOTICE_RECOVER_WAL", |
| 457 | )<SQLiteErrorProps> {} |
| 458 | |
| 459 | // ============================================================================= |
| 460 | // Extended Result Codes - READONLY |
| 461 | // ============================================================================= |
| 462 | |
| 463 | export class SQLiteReadonlyCantinit extends Data.TaggedError( |
| 464 | "SQLITE_READONLY_CANTINIT", |
| 465 | )<SQLiteErrorProps> {} |
| 466 | export class SQLiteReadonlyCantlock extends Data.TaggedError( |
| 467 | "SQLITE_READONLY_CANTLOCK", |
| 468 | )<SQLiteErrorProps> {} |
| 469 | export class SQLiteReadonlyDbmoved extends Data.TaggedError( |
| 470 | "SQLITE_READONLY_DBMOVED", |
| 471 | )<SQLiteErrorProps> {} |
| 472 | export class SQLiteReadonlyDirectory extends Data.TaggedError( |
| 473 | "SQLITE_READONLY_DIRECTORY", |
| 474 | )<SQLiteErrorProps> {} |
| 475 | export class SQLiteReadonlyRecovery extends Data.TaggedError( |
| 476 | "SQLITE_READONLY_RECOVERY", |
| 477 | )<SQLiteErrorProps> {} |
| 478 | export class SQLiteReadonlyRollback extends Data.TaggedError( |
| 479 | "SQLITE_READONLY_ROLLBACK", |
| 480 | )<SQLiteErrorProps> {} |
| 481 | |
| 482 | // ============================================================================= |
| 483 | // Extended Result Codes - WARNING |
| 484 | // ============================================================================= |
| 485 | |
| 486 | export class SQLiteWarningAutoindex extends Data.TaggedError( |
| 487 | "SQLITE_WARNING_AUTOINDEX", |
| 488 | )<SQLiteErrorProps> {} |
| 489 | |
| 490 | // ============================================================================= |
| 491 | // Unknown Error (fallback) |
| 492 | // ============================================================================= |
| 493 | |
| 494 | /** |
| 495 | * Fallback for unknown or unrecognized SQLite error codes. |
| 496 | */ |
| 497 | export class SQLiteUnknownError extends Data.TaggedError("SQLITE_UNKNOWN")< |
| 498 | SQLiteErrorProps & { |
| 499 | readonly code?: string; |
| 500 | } |
| 501 | > {} |
| 502 | |
| 503 | // ============================================================================= |
| 504 | // Union Type |
| 505 | // ============================================================================= |
| 506 | |
| 507 | /** |
| 508 | * Union of all SQLite error types. |
| 509 | */ |
| 510 | export type SQLiteErrorType = |
| 511 | // Primary result codes |
| 512 | | SQLiteError |
| 513 | | SQLiteInternal |
| 514 | | SQLitePerm |
| 515 | | SQLiteAbort |
| 516 | | SQLiteBusy |
| 517 | | SQLiteLocked |
| 518 | | SQLiteNomem |
| 519 | | SQLiteReadonly |
| 520 | | SQLiteInterrupt |
| 521 | | SQLiteIoerr |
| 522 | | SQLiteCorrupt |
| 523 | | SQLiteNotfound |
| 524 | | SQLiteFull |
| 525 | | SQLiteCantopen |
| 526 | | SQLiteProtocol |
| 527 | | SQLiteEmpty |
| 528 | | SQLiteSchema |
| 529 | | SQLiteToobig |
| 530 | | SQLiteConstraint |
| 531 | | SQLiteMismatch |
| 532 | | SQLiteMisuse |
| 533 | | SQLiteNolfs |
| 534 | | SQLiteAuth |
| 535 | | SQLiteFormat |
| 536 | | SQLiteRange |
| 537 | | SQLiteNotadb |
| 538 | | SQLiteNotice |
| 539 | | SQLiteWarning |
| 540 | // Extended - ABORT |
| 541 | | SQLiteAbortRollback |
| 542 | // Extended - AUTH |
| 543 | | SQLiteAuthUser |
| 544 | // Extended - BUSY |
| 545 | | SQLiteBusyRecovery |
| 546 | | SQLiteBusySnapshot |
| 547 | | SQLiteBusyTimeout |
| 548 | // Extended - CANTOPEN |
| 549 | | SQLiteCantopenConvpath |
| 550 | | SQLiteCantopenDirtywal |
| 551 | | SQLiteCantopenFullpath |
| 552 | | SQLiteCantopenIsdir |
| 553 | | SQLiteCantopenNotempdir |
| 554 | | SQLiteCantopenSymlink |
| 555 | // Extended - CONSTRAINT |
| 556 | | SQLiteConstraintCheck |
| 557 | | SQLiteConstraintCommithook |
| 558 | | SQLiteConstraintDatatype |
| 559 | | SQLiteConstraintForeignkey |
| 560 | | SQLiteConstraintFunction |
| 561 | | SQLiteConstraintNotnull |
| 562 | | SQLiteConstraintPinned |
| 563 | | SQLiteConstraintPrimarykey |
| 564 | | SQLiteConstraintRowid |
| 565 | | SQLiteConstraintTrigger |
| 566 | | SQLiteConstraintUnique |
| 567 | | SQLiteConstraintVtab |
| 568 | // Extended - CORRUPT |
| 569 | | SQLiteCorruptIndex |
| 570 | | SQLiteCorruptSequence |
| 571 | | SQLiteCorruptVtab |
| 572 | // Extended - ERROR |
| 573 | | SQLiteErrorMissingCollseq |
| 574 | | SQLiteErrorRetry |
| 575 | | SQLiteErrorSnapshot |
| 576 | // Extended - IOERR |
| 577 | | SQLiteIoerrAccess |
| 578 | | SQLiteIoerrAuth |
| 579 | | SQLiteIoerrBeginAtomic |
| 580 | | SQLiteIoerrBlocked |
| 581 | | SQLiteIoerrCheckreservedlock |
| 582 | | SQLiteIoerrClose |
| 583 | | SQLiteIoerrCommitAtomic |
| 584 | | SQLiteIoerrConvpath |
| 585 | | SQLiteIoerrCorruptfs |
| 586 | | SQLiteIoerrData |
| 587 | | SQLiteIoerrDelete |
| 588 | | SQLiteIoerrDeleteNoent |
| 589 | | SQLiteIoerrDirClose |
| 590 | | SQLiteIoerrDirFsync |
| 591 | | SQLiteIoerrFstat |
| 592 | | SQLiteIoerrFsync |
| 593 | | SQLiteIoerrGettemppath |
| 594 | | SQLiteIoerrLock |
| 595 | | SQLiteIoerrMmap |
| 596 | | SQLiteIoerrNomem |
| 597 | | SQLiteIoerrRdlock |
| 598 | | SQLiteIoerrRead |
| 599 | | SQLiteIoerrRollbackAtomic |
| 600 | | SQLiteIoerrSeek |
| 601 | | SQLiteIoerrShmlock |
| 602 | | SQLiteIoerrShmmap |
| 603 | | SQLiteIoerrShmopen |
| 604 | | SQLiteIoerrShmsize |
| 605 | | SQLiteIoerrShortRead |
| 606 | | SQLiteIoerrTruncate |
| 607 | | SQLiteIoerrUnlock |
| 608 | | SQLiteIoerrVnode |
| 609 | | SQLiteIoerrWrite |
| 610 | // Extended - LOCKED |
| 611 | | SQLiteLockedSharedcache |
| 612 | | SQLiteLockedVtab |
| 613 | // Extended - NOTICE |
| 614 | | SQLiteNoticeRecoverRollback |
| 615 | | SQLiteNoticeRecoverWal |
| 616 | // Extended - READONLY |
| 617 | | SQLiteReadonlyCantinit |
| 618 | | SQLiteReadonlyCantlock |
| 619 | | SQLiteReadonlyDbmoved |
| 620 | | SQLiteReadonlyDirectory |
| 621 | | SQLiteReadonlyRecovery |
| 622 | | SQLiteReadonlyRollback |
| 623 | // Extended - WARNING |
| 624 | | SQLiteWarningAutoindex |
| 625 | // Unknown |
| 626 | | SQLiteUnknownError; |
| 627 | |
| 628 | // ============================================================================= |
| 629 | // Helper Functions |
| 630 | // ============================================================================= |
| 631 | |
| 632 | /** |
| 633 | * Type guard to check if an error is a SQLite error with a _tag. |
| 634 | */ |
| 635 | export const isSQLiteError = (error: unknown): error is SQLiteErrorType => { |
| 636 | return ( |
| 637 | typeof error === "object" && |
| 638 | error !== null && |
| 639 | "_tag" in error && |
| 640 | typeof error._tag === "string" && |
| 641 | error._tag.startsWith("SQLITE_") |
| 642 | ); |
| 643 | }; |
| 644 | |
| 645 | /** |
| 646 | * Check if the error is retryable (busy or locked errors). |
| 647 | */ |
| 648 | export const isRetryable = (e: SQLiteErrorType): boolean => { |
| 649 | switch (e._tag) { |
| 650 | case "SQLITE_BUSY": |
| 651 | case "SQLITE_BUSY_RECOVERY": |
| 652 | case "SQLITE_BUSY_SNAPSHOT": |
| 653 | case "SQLITE_BUSY_TIMEOUT": |
| 654 | case "SQLITE_LOCKED": |
| 655 | case "SQLITE_LOCKED_SHAREDCACHE": |
| 656 | case "SQLITE_LOCKED_VTAB": |
| 657 | return true; |
| 658 | default: |
| 659 | return false; |
| 660 | } |
| 661 | }; |
| 662 | |
| 663 | /** |
| 664 | * Parse an error from a SQLite client into a typed error. |
| 665 | */ |
| 666 | export const parseError = ( |
| 667 | code: string | undefined, |
| 668 | message: string, |
| 669 | cause?: unknown, |
| 670 | ): SQLiteErrorType => { |
| 671 | switch (code) { |
| 672 | // Primary result codes |
| 673 | case "SQLITE_ERROR": |
| 674 | return new SQLiteError({ message, cause }); |
| 675 | case "SQLITE_INTERNAL": |
| 676 | return new SQLiteInternal({ message, cause }); |
| 677 | case "SQLITE_PERM": |
| 678 | return new SQLitePerm({ message, cause }); |
| 679 | case "SQLITE_ABORT": |
| 680 | return new SQLiteAbort({ message, cause }); |
| 681 | case "SQLITE_BUSY": |
| 682 | return new SQLiteBusy({ message, cause }); |
| 683 | case "SQLITE_LOCKED": |
| 684 | return new SQLiteLocked({ message, cause }); |
| 685 | case "SQLITE_NOMEM": |
| 686 | return new SQLiteNomem({ message, cause }); |
| 687 | case "SQLITE_READONLY": |
| 688 | return new SQLiteReadonly({ message, cause }); |
| 689 | case "SQLITE_INTERRUPT": |
| 690 | return new SQLiteInterrupt({ message, cause }); |
| 691 | case "SQLITE_IOERR": |
| 692 | return new SQLiteIoerr({ message, cause }); |
| 693 | case "SQLITE_CORRUPT": |
| 694 | return new SQLiteCorrupt({ message, cause }); |
| 695 | case "SQLITE_NOTFOUND": |
| 696 | return new SQLiteNotfound({ message, cause }); |
| 697 | case "SQLITE_FULL": |
| 698 | return new SQLiteFull({ message, cause }); |
| 699 | case "SQLITE_CANTOPEN": |
| 700 | return new SQLiteCantopen({ message, cause }); |
| 701 | case "SQLITE_PROTOCOL": |
| 702 | return new SQLiteProtocol({ message, cause }); |
| 703 | case "SQLITE_EMPTY": |
| 704 | return new SQLiteEmpty({ message, cause }); |
| 705 | case "SQLITE_SCHEMA": |
| 706 | return new SQLiteSchema({ message, cause }); |
| 707 | case "SQLITE_TOOBIG": |
| 708 | return new SQLiteToobig({ message, cause }); |
| 709 | case "SQLITE_CONSTRAINT": |
| 710 | return new SQLiteConstraint({ message, cause }); |
| 711 | case "SQLITE_MISMATCH": |
| 712 | return new SQLiteMismatch({ message, cause }); |
| 713 | case "SQLITE_MISUSE": |
| 714 | return new SQLiteMisuse({ message, cause }); |
| 715 | case "SQLITE_NOLFS": |
| 716 | return new SQLiteNolfs({ message, cause }); |
| 717 | case "SQLITE_AUTH": |
| 718 | return new SQLiteAuth({ message, cause }); |
| 719 | case "SQLITE_FORMAT": |
| 720 | return new SQLiteFormat({ message, cause }); |
| 721 | case "SQLITE_RANGE": |
| 722 | return new SQLiteRange({ message, cause }); |
| 723 | case "SQLITE_NOTADB": |
| 724 | return new SQLiteNotadb({ message, cause }); |
| 725 | case "SQLITE_NOTICE": |
| 726 | return new SQLiteNotice({ message, cause }); |
| 727 | case "SQLITE_WARNING": |
| 728 | return new SQLiteWarning({ message, cause }); |
| 729 | |
| 730 | // Extended - ABORT |
| 731 | case "SQLITE_ABORT_ROLLBACK": |
| 732 | return new SQLiteAbortRollback({ message, cause }); |
| 733 | |
| 734 | // Extended - AUTH |
| 735 | case "SQLITE_AUTH_USER": |
| 736 | return new SQLiteAuthUser({ message, cause }); |
| 737 | |
| 738 | // Extended - BUSY |
| 739 | case "SQLITE_BUSY_RECOVERY": |
| 740 | return new SQLiteBusyRecovery({ message, cause }); |
| 741 | case "SQLITE_BUSY_SNAPSHOT": |
| 742 | return new SQLiteBusySnapshot({ message, cause }); |
| 743 | case "SQLITE_BUSY_TIMEOUT": |
| 744 | return new SQLiteBusyTimeout({ message, cause }); |
| 745 | |
| 746 | // Extended - CANTOPEN |
| 747 | case "SQLITE_CANTOPEN_CONVPATH": |
| 748 | return new SQLiteCantopenConvpath({ message, cause }); |
| 749 | case "SQLITE_CANTOPEN_DIRTYWAL": |
| 750 | return new SQLiteCantopenDirtywal({ message, cause }); |
| 751 | case "SQLITE_CANTOPEN_FULLPATH": |
| 752 | return new SQLiteCantopenFullpath({ message, cause }); |
| 753 | case "SQLITE_CANTOPEN_ISDIR": |
| 754 | return new SQLiteCantopenIsdir({ message, cause }); |
| 755 | case "SQLITE_CANTOPEN_NOTEMPDIR": |
| 756 | return new SQLiteCantopenNotempdir({ message, cause }); |
| 757 | case "SQLITE_CANTOPEN_SYMLINK": |
| 758 | return new SQLiteCantopenSymlink({ message, cause }); |
| 759 | |
| 760 | // Extended - CONSTRAINT |
| 761 | case "SQLITE_CONSTRAINT_CHECK": |
| 762 | return new SQLiteConstraintCheck({ message, cause }); |
| 763 | case "SQLITE_CONSTRAINT_COMMITHOOK": |
| 764 | return new SQLiteConstraintCommithook({ message, cause }); |
| 765 | case "SQLITE_CONSTRAINT_DATATYPE": |
| 766 | return new SQLiteConstraintDatatype({ message, cause }); |
| 767 | case "SQLITE_CONSTRAINT_FOREIGNKEY": |
| 768 | return new SQLiteConstraintForeignkey({ message, cause }); |
| 769 | case "SQLITE_CONSTRAINT_FUNCTION": |
| 770 | return new SQLiteConstraintFunction({ message, cause }); |
| 771 | case "SQLITE_CONSTRAINT_NOTNULL": |
| 772 | return new SQLiteConstraintNotnull({ message, cause }); |
| 773 | case "SQLITE_CONSTRAINT_PINNED": |
| 774 | return new SQLiteConstraintPinned({ message, cause }); |
| 775 | case "SQLITE_CONSTRAINT_PRIMARYKEY": |
| 776 | return new SQLiteConstraintPrimarykey({ message, cause }); |
| 777 | case "SQLITE_CONSTRAINT_ROWID": |
| 778 | return new SQLiteConstraintRowid({ message, cause }); |
| 779 | case "SQLITE_CONSTRAINT_TRIGGER": |
| 780 | return new SQLiteConstraintTrigger({ message, cause }); |
| 781 | case "SQLITE_CONSTRAINT_UNIQUE": |
| 782 | return new SQLiteConstraintUnique({ message, cause }); |
| 783 | case "SQLITE_CONSTRAINT_VTAB": |
| 784 | return new SQLiteConstraintVtab({ message, cause }); |
| 785 | |
| 786 | // Extended - CORRUPT |
| 787 | case "SQLITE_CORRUPT_INDEX": |
| 788 | return new SQLiteCorruptIndex({ message, cause }); |
| 789 | case "SQLITE_CORRUPT_SEQUENCE": |
| 790 | return new SQLiteCorruptSequence({ message, cause }); |
| 791 | case "SQLITE_CORRUPT_VTAB": |
| 792 | return new SQLiteCorruptVtab({ message, cause }); |
| 793 | |
| 794 | // Extended - ERROR |
| 795 | case "SQLITE_ERROR_MISSING_COLLSEQ": |
| 796 | return new SQLiteErrorMissingCollseq({ message, cause }); |
| 797 | case "SQLITE_ERROR_RETRY": |
| 798 | return new SQLiteErrorRetry({ message, cause }); |
| 799 | case "SQLITE_ERROR_SNAPSHOT": |
| 800 | return new SQLiteErrorSnapshot({ message, cause }); |
| 801 | |
| 802 | // Extended - IOERR |
| 803 | case "SQLITE_IOERR_ACCESS": |
| 804 | return new SQLiteIoerrAccess({ message, cause }); |
| 805 | case "SQLITE_IOERR_AUTH": |
| 806 | return new SQLiteIoerrAuth({ message, cause }); |
| 807 | case "SQLITE_IOERR_BEGIN_ATOMIC": |
| 808 | return new SQLiteIoerrBeginAtomic({ message, cause }); |
| 809 | case "SQLITE_IOERR_BLOCKED": |
| 810 | return new SQLiteIoerrBlocked({ message, cause }); |
| 811 | case "SQLITE_IOERR_CHECKRESERVEDLOCK": |
| 812 | return new SQLiteIoerrCheckreservedlock({ message, cause }); |
| 813 | case "SQLITE_IOERR_CLOSE": |
| 814 | return new SQLiteIoerrClose({ message, cause }); |
| 815 | case "SQLITE_IOERR_COMMIT_ATOMIC": |
| 816 | return new SQLiteIoerrCommitAtomic({ message, cause }); |
| 817 | case "SQLITE_IOERR_CONVPATH": |
| 818 | return new SQLiteIoerrConvpath({ message, cause }); |
| 819 | case "SQLITE_IOERR_CORRUPTFS": |
| 820 | return new SQLiteIoerrCorruptfs({ message, cause }); |
| 821 | case "SQLITE_IOERR_DATA": |
| 822 | return new SQLiteIoerrData({ message, cause }); |
| 823 | case "SQLITE_IOERR_DELETE": |
| 824 | return new SQLiteIoerrDelete({ message, cause }); |
| 825 | case "SQLITE_IOERR_DELETE_NOENT": |
| 826 | return new SQLiteIoerrDeleteNoent({ message, cause }); |
| 827 | case "SQLITE_IOERR_DIR_CLOSE": |
| 828 | return new SQLiteIoerrDirClose({ message, cause }); |
| 829 | case "SQLITE_IOERR_DIR_FSYNC": |
| 830 | return new SQLiteIoerrDirFsync({ message, cause }); |
| 831 | case "SQLITE_IOERR_FSTAT": |
| 832 | return new SQLiteIoerrFstat({ message, cause }); |
| 833 | case "SQLITE_IOERR_FSYNC": |
| 834 | return new SQLiteIoerrFsync({ message, cause }); |
| 835 | case "SQLITE_IOERR_GETTEMPPATH": |
| 836 | return new SQLiteIoerrGettemppath({ message, cause }); |
| 837 | case "SQLITE_IOERR_LOCK": |
| 838 | return new SQLiteIoerrLock({ message, cause }); |
| 839 | case "SQLITE_IOERR_MMAP": |
| 840 | return new SQLiteIoerrMmap({ message, cause }); |
| 841 | case "SQLITE_IOERR_NOMEM": |
| 842 | return new SQLiteIoerrNomem({ message, cause }); |
| 843 | case "SQLITE_IOERR_RDLOCK": |
| 844 | return new SQLiteIoerrRdlock({ message, cause }); |
| 845 | case "SQLITE_IOERR_READ": |
| 846 | return new SQLiteIoerrRead({ message, cause }); |
| 847 | case "SQLITE_IOERR_ROLLBACK_ATOMIC": |
| 848 | return new SQLiteIoerrRollbackAtomic({ message, cause }); |
| 849 | case "SQLITE_IOERR_SEEK": |
| 850 | return new SQLiteIoerrSeek({ message, cause }); |
| 851 | case "SQLITE_IOERR_SHMLOCK": |
| 852 | return new SQLiteIoerrShmlock({ message, cause }); |
| 853 | case "SQLITE_IOERR_SHMMAP": |
| 854 | return new SQLiteIoerrShmmap({ message, cause }); |
| 855 | case "SQLITE_IOERR_SHMOPEN": |
| 856 | return new SQLiteIoerrShmopen({ message, cause }); |
| 857 | case "SQLITE_IOERR_SHMSIZE": |
| 858 | return new SQLiteIoerrShmsize({ message, cause }); |
| 859 | case "SQLITE_IOERR_SHORT_READ": |
| 860 | return new SQLiteIoerrShortRead({ message, cause }); |
| 861 | case "SQLITE_IOERR_TRUNCATE": |
| 862 | return new SQLiteIoerrTruncate({ message, cause }); |
| 863 | case "SQLITE_IOERR_UNLOCK": |
| 864 | return new SQLiteIoerrUnlock({ message, cause }); |
| 865 | case "SQLITE_IOERR_VNODE": |
| 866 | return new SQLiteIoerrVnode({ message, cause }); |
| 867 | case "SQLITE_IOERR_WRITE": |
| 868 | return new SQLiteIoerrWrite({ message, cause }); |
| 869 | |
| 870 | // Extended - LOCKED |
| 871 | case "SQLITE_LOCKED_SHAREDCACHE": |
| 872 | return new SQLiteLockedSharedcache({ message, cause }); |
| 873 | case "SQLITE_LOCKED_VTAB": |
| 874 | return new SQLiteLockedVtab({ message, cause }); |
| 875 | |
| 876 | // Extended - NOTICE |
| 877 | case "SQLITE_NOTICE_RECOVER_ROLLBACK": |
| 878 | return new SQLiteNoticeRecoverRollback({ message, cause }); |
| 879 | case "SQLITE_NOTICE_RECOVER_WAL": |
| 880 | return new SQLiteNoticeRecoverWal({ message, cause }); |
| 881 | |
| 882 | // Extended - READONLY |
| 883 | case "SQLITE_READONLY_CANTINIT": |
| 884 | return new SQLiteReadonlyCantinit({ message, cause }); |
| 885 | case "SQLITE_READONLY_CANTLOCK": |
| 886 | return new SQLiteReadonlyCantlock({ message, cause }); |
| 887 | case "SQLITE_READONLY_DBMOVED": |
| 888 | return new SQLiteReadonlyDbmoved({ message, cause }); |
| 889 | case "SQLITE_READONLY_DIRECTORY": |
| 890 | return new SQLiteReadonlyDirectory({ message, cause }); |
| 891 | case "SQLITE_READONLY_RECOVERY": |
| 892 | return new SQLiteReadonlyRecovery({ message, cause }); |
| 893 | case "SQLITE_READONLY_ROLLBACK": |
| 894 | return new SQLiteReadonlyRollback({ message, cause }); |
| 895 | |
| 896 | // Extended - WARNING |
| 897 | case "SQLITE_WARNING_AUTOINDEX": |
| 898 | return new SQLiteWarningAutoindex({ message, cause }); |
| 899 | |
| 900 | // Unknown/default |
| 901 | default: |
| 902 | return new SQLiteUnknownError({ message, cause, code }); |
| 903 | } |
| 904 | }; |