summaryrefslogtreecommitdiff
path: root/internal/db/bundb/errors.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/db/bundb/errors.go')
-rw-r--r--internal/db/bundb/errors.go22
1 files changed, 9 insertions, 13 deletions
diff --git a/internal/db/bundb/errors.go b/internal/db/bundb/errors.go
index 7d0157373..1c0f8a7ff 100644
--- a/internal/db/bundb/errors.go
+++ b/internal/db/bundb/errors.go
@@ -1,10 +1,11 @@
package bundb
import (
+ "errors"
+
"github.com/jackc/pgconn"
+ "github.com/mattn/go-sqlite3"
"github.com/superseriousbusiness/gotosocial/internal/db"
- "modernc.org/sqlite"
- sqlite3 "modernc.org/sqlite/lib"
)
// processPostgresError processes an error, replacing any postgres specific errors with our own error type
@@ -27,17 +28,12 @@ func processPostgresError(err error) db.Error {
// processSQLiteError processes an error, replacing any sqlite specific errors with our own error type
func processSQLiteError(err error) db.Error {
- // Attempt to cast as sqlite
- sqliteErr, ok := err.(*sqlite.Error)
- if !ok {
- return err
+ var sqlError sqlite3.Error
+ if errors.As(err, &sqlError) {
+ if sqlError.Code == sqlite3.ErrConstraint && (sqlError.ExtendedCode == sqlite3.ErrConstraintUnique || sqlError.ExtendedCode == sqlite3.ErrConstraintPrimaryKey) {
+ return db.ErrAlreadyExists
+ }
}
- // Handle supplied error code:
- switch sqliteErr.Code() {
- case sqlite3.SQLITE_CONSTRAINT_UNIQUE, sqlite3.SQLITE_CONSTRAINT_PRIMARYKEY:
- return db.ErrAlreadyExists
- default:
- return err
- }
+ return err
}