snapshot of https://github.com/ory/keto.git (master, 2026-09-16; blobs > 131072B omitted)
Some checks failed
CI / Run lints and checks (push) Failing after 47s
CI / Run tests (push) Failing after 1s
CI / Run race tests (push) Failing after 5s
CI / Build CLI docs (push) Has been skipped
CI / Run buf actions (push) Failing after 5s
CodeQL / Analyze (go) (push) Failing after 3s
CodeQL / Analyze (javascript) (push) Failing after 2s
Docker Image Scanners / scanners (push) Failing after 3s
Format / format (push) Failing after 3s
Synchronize Issue Labels / Synchronize Issue Labels (push) Has been skipped
CI / Generate release (push) Has been skipped
CI / Draft newsletter (push) Has been skipped
CI / Pending approval Slack notification (push) Has been skipped
CI / Send newsletter (push) Has been skipped
Some checks failed
CI / Run lints and checks (push) Failing after 47s
CI / Run tests (push) Failing after 1s
CI / Run race tests (push) Failing after 5s
CI / Build CLI docs (push) Has been skipped
CI / Run buf actions (push) Failing after 5s
CodeQL / Analyze (go) (push) Failing after 3s
CodeQL / Analyze (javascript) (push) Failing after 2s
Docker Image Scanners / scanners (push) Failing after 3s
Format / format (push) Failing after 3s
Synchronize Issue Labels / Synchronize Issue Labels (push) Has been skipped
CI / Generate release (push) Has been skipped
CI / Draft newsletter (push) Has been skipped
CI / Pending approval Slack notification (push) Has been skipped
CI / Send newsletter (push) Has been skipped
This commit is contained in:
47
oryx/sqlcon/error_sqlite.go
Normal file
47
oryx/sqlcon/error_sqlite.go
Normal file
@@ -0,0 +1,47 @@
|
||||
// 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)
|
||||
}
|
||||
Reference in New Issue
Block a user