(
cause: unknown,
{ message, operation }: SqliteClassifyOptions = {}
)
| 555 | * @since 4.0.0 |
| 556 | */ |
| 557 | export const classifySqliteError = ( |
| 558 | cause: unknown, |
| 559 | { message, operation }: SqliteClassifyOptions = {} |
| 560 | ): SqlErrorReason => { |
| 561 | const props = { |
| 562 | cause, |
| 563 | message, |
| 564 | operation |
| 565 | } |
| 566 | const code = sqliteCodeFromCause(cause) |
| 567 | const numericCode = sqliteNumericCodeFromCause(cause) |
| 568 | |
| 569 | if (code === SQLITE_CONSTRAINT_UNIQUE || matchesSqliteNumericCode(cause, SQLITE_CONSTRAINT_UNIQUE_CODE)) { |
| 570 | return new UniqueViolation({ ...props, constraint: sqliteUniqueConstraintFromCause(cause) }) |
| 571 | } |
| 572 | |
| 573 | if (typeof code === "string") { |
| 574 | if (matchesSqliteCode(code, "SQLITE_AUTH")) { |
| 575 | return new AuthenticationError(props) |
| 576 | } |
| 577 | if (matchesSqliteCode(code, "SQLITE_PERM")) { |
| 578 | return new AuthorizationError(props) |
| 579 | } |
| 580 | if (matchesSqliteCode(code, "SQLITE_CONSTRAINT")) { |
| 581 | return new ConstraintError(props) |
| 582 | } |
| 583 | if (matchesSqliteCode(code, "SQLITE_BUSY") || matchesSqliteCode(code, "SQLITE_LOCKED")) { |
| 584 | return new LockTimeoutError(props) |
| 585 | } |
| 586 | if (matchesSqliteCode(code, "SQLITE_CANTOPEN")) { |
| 587 | return new ConnectionError(props) |
| 588 | } |
| 589 | } |
| 590 | |
| 591 | if (typeof numericCode === "number") { |
| 592 | const code = numericCode & 0xff |
| 593 | switch (code) { |
| 594 | case 23: |
| 595 | return new AuthenticationError(props) |
| 596 | case 3: |
| 597 | return new AuthorizationError(props) |
| 598 | case 19: |
| 599 | return new ConstraintError(props) |
| 600 | case 5: |
| 601 | case 6: |
| 602 | return new LockTimeoutError(props) |
| 603 | case 14: |
| 604 | return new ConnectionError(props) |
| 605 | default: |
| 606 | return new UnknownError(props) |
| 607 | } |
| 608 | } |
| 609 | |
| 610 | return new UnknownError(props) |
| 611 | } |
| 612 | |
| 613 | /** |
| 614 | * Error raised when an ordered batched SQL resolver receives a different number |
no test coverage detected