Files
upstream-ory-kratos/oryx/sqlcon/error_sqlite.go
upstream-mirror c60cc7ca75
Some checks failed
CI / Run tests and lints (push) Failing after 29s
CI / Build CLI docs (push) Has been skipped
CI / Run Playwright end-to-end tests (mysql) (push) Failing after 3s
CI / Run Playwright end-to-end tests (postgres) (push) Failing after 2s
CI / Run Playwright end-to-end tests (sqlite) (push) Failing after 3s
CodeQL / Analyze (go) (push) Failing after 4s
CodeQL / Analyze (javascript) (push) Failing after 3s
Docker Image Scanners / scanners (push) Failing after 4s
Synchronize Issue Labels / Synchronize Issue Labels (push) Has been skipped
CI / Run end-to-end tests (postgres) (push) Failing after 19s
CI / Run end-to-end tests (sqlite) (push) Failing after 2s
CI / Run Playwright end-to-end tests (cockroach) (push) Failing after 2s
CI / Draft newsletter (push) Has been skipped
CI / Generate release (push) Has been skipped
CI / Pending approval Slack notification (push) Has been skipped
CI / Send newsletter (push) Has been skipped
snapshot of https://github.com/ory/kratos.git (master, 2026-09-15; blobs > 131072B omitted)
2026-09-15 21:19:12 +05:00

48 lines
1.5 KiB
Go

// Copyright © 2023 Ory Corp
// SPDX-License-Identifier: Apache-2.0
package sqlcon
import (
"strings"
"github.com/pkg/errors"
"modernc.org/sqlite"
sqlite3lib "modernc.org/sqlite/lib"
)
// isSqliteForeignKeyViolation reports whether e is an SQLite foreign-key
// constraint failure. SQLite's extended result code for this case is not
// reported consistently by the driver, so we match on the stable error
// message instead.
func isSqliteForeignKeyViolation(e *sqlite.Error) bool {
return strings.Contains(e.Error(), "FOREIGN KEY constraint failed")
}
// handleSqlite handles the error iff (if and only if) it is an sqlite error
func handleSqlite(e *sqlite.Error, err error) error {
// Code() returns the full extended error code.
switch e.Code() {
case sqlite3lib.SQLITE_CONSTRAINT_UNIQUE,
sqlite3lib.SQLITE_CONSTRAINT_PRIMARYKEY:
return errors.WithStack(ErrUniqueViolation().WithWrap(err))
case sqlite3lib.SQLITE_ERROR:
if strings.Contains(e.Error(), "no such table") {
return errors.WithStack(ErrNoSuchTable().WithWrap(err))
}
case sqlite3lib.SQLITE_LOCKED,
sqlite3lib.SQLITE_BUSY,
sqlite3lib.SQLITE_BUSY_RECOVERY,
sqlite3lib.SQLITE_BUSY_SNAPSHOT,
sqlite3lib.SQLITE_BUSY_TIMEOUT:
return errors.WithStack(ErrConcurrentUpdate().WithWrap(err))
}
if strings.HasPrefix(e.Error(), "no such column:") ||
strings.Contains(e.Error(), "has no column named") {
return errors.WithStack(ErrNoSuchColumn().WithWrap(err))
}
return errors.WithStack(err)
}