(
cause: unknown,
{ message, operation }: SqliteClassifyOptions = {}
)
| 511 | * @since 4.0.0 |
| 512 | */ |
| 513 | export const classifySqliteError = ( |
| 514 | cause: unknown, |
| 515 | { message, operation }: SqliteClassifyOptions = {} |
| 516 | ): SqlErrorReason => { |
| 517 | const props = { |
| 518 | cause, |
| 519 | message, |
| 520 | operation |
| 521 | } |
| 522 | const code = sqliteCodeFromCause(cause) |
| 523 | const numericCode = sqliteNumericCodeFromCause(cause) |
| 524 | |
| 525 | if (code === SQLITE_CONSTRAINT_UNIQUE || matchesSqliteNumericCode(cause, SQLITE_CONSTRAINT_UNIQUE_CODE)) { |
| 526 | return new UniqueViolation({ ...props, constraint: sqliteUniqueConstraintFromCause(cause) }) |
| 527 | } |
| 528 | |
| 529 | if (typeof code === "string") { |
| 530 | if (matchesSqliteCode(code, "SQLITE_AUTH")) { |
| 531 | return new AuthenticationError(props) |
| 532 | } |
| 533 | if (matchesSqliteCode(code, "SQLITE_PERM")) { |
| 534 | return new AuthorizationError(props) |
| 535 | } |
| 536 | if (matchesSqliteCode(code, "SQLITE_CONSTRAINT")) { |
| 537 | return new ConstraintError(props) |
| 538 | } |
| 539 | if (matchesSqliteCode(code, "SQLITE_BUSY") || matchesSqliteCode(code, "SQLITE_LOCKED")) { |
| 540 | return new LockTimeoutError(props) |
| 541 | } |
| 542 | if (matchesSqliteCode(code, "SQLITE_CANTOPEN")) { |
| 543 | return new ConnectionError(props) |
| 544 | } |
| 545 | } |
| 546 | |
| 547 | if (typeof numericCode === "number") { |
| 548 | const code = numericCode & 0xff |
| 549 | switch (code) { |
| 550 | case 23: |
| 551 | return new AuthenticationError(props) |
| 552 | case 3: |
| 553 | return new AuthorizationError(props) |
| 554 | case 19: |
| 555 | return new ConstraintError(props) |
| 556 | case 5: |
| 557 | case 6: |
| 558 | return new LockTimeoutError(props) |
| 559 | case 14: |
| 560 | return new ConnectionError(props) |
| 561 | default: |
| 562 | return new UnknownError(props) |
| 563 | } |
| 564 | } |
| 565 | |
| 566 | return new UnknownError(props) |
| 567 | } |
| 568 | |
| 569 | /** |
| 570 | * Error raised when an ordered batched SQL resolver receives a different number |
no test coverage detected