From be3d4cdacb512b2feb72bead1e50797a990e7dd6 Mon Sep 17 00:00:00 2001 From: Till Faelligen Date: Mon, 1 Jun 2020 18:05:49 +0200 Subject: [PATCH] Move ErrUserExists to accounts package --- appservice/appservice.go | 3 +-- clientapi/auth/storage/accounts/interface.go | 3 +++ clientapi/auth/storage/accounts/postgres/storage.go | 3 ++- clientapi/auth/storage/accounts/sqlite3/storage.go | 3 ++- clientapi/routing/register.go | 2 +- internal/sql.go | 4 ---- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/appservice/appservice.go b/appservice/appservice.go index 68cf52e79..1cd5d57fa 100644 --- a/appservice/appservice.go +++ b/appservice/appservice.go @@ -30,7 +30,6 @@ import ( "github.com/matrix-org/dendrite/appservice/workers" "github.com/matrix-org/dendrite/clientapi/auth/storage/accounts" "github.com/matrix-org/dendrite/clientapi/auth/storage/devices" - "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/internal/basecomponent" "github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/dendrite/internal/transactions" @@ -121,7 +120,7 @@ func generateAppServiceAccount( // Create an account for the application service _, err := accountsDB.CreateAccount(ctx, as.SenderLocalpart, "", as.ID) if err != nil { - if errors.Is(err, internal.ErrUserExists) { // This account already exists + if errors.Is(err, accounts.ErrUserExists) { // This account already exists return nil } return err diff --git a/clientapi/auth/storage/accounts/interface.go b/clientapi/auth/storage/accounts/interface.go index 4d1941a23..7e1313850 100644 --- a/clientapi/auth/storage/accounts/interface.go +++ b/clientapi/auth/storage/accounts/interface.go @@ -55,3 +55,6 @@ type Database interface { // Err3PIDInUse is the error returned when trying to save an association involving // a third-party identifier which is already associated to a local user. var Err3PIDInUse = errors.New("This third-party identifier is already in use") + +// ErrUserExists is returned if a username already exists in the database. +var ErrUserExists = errors.New("Username already exists") diff --git a/clientapi/auth/storage/accounts/postgres/storage.go b/clientapi/auth/storage/accounts/postgres/storage.go index 4be5dca94..d961ab1f1 100644 --- a/clientapi/auth/storage/accounts/postgres/storage.go +++ b/clientapi/auth/storage/accounts/postgres/storage.go @@ -21,6 +21,7 @@ import ( "strconv" "github.com/matrix-org/dendrite/clientapi/auth/authtypes" + "github.com/matrix-org/dendrite/clientapi/auth/storage/accounts" "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/internal/sqlutil" "github.com/matrix-org/gomatrixserverlib" @@ -164,7 +165,7 @@ func (d *Database) createAccount( } if err := d.profiles.insertProfile(ctx, txn, localpart); err != nil { if internal.IsUniqueConstraintViolationErr(err) { - return nil, internal.ErrUserExists + return nil, accounts.ErrUserExists } return nil, err } diff --git a/clientapi/auth/storage/accounts/sqlite3/storage.go b/clientapi/auth/storage/accounts/sqlite3/storage.go index 4b4367082..0b5542796 100644 --- a/clientapi/auth/storage/accounts/sqlite3/storage.go +++ b/clientapi/auth/storage/accounts/sqlite3/storage.go @@ -22,6 +22,7 @@ import ( "sync" "github.com/matrix-org/dendrite/clientapi/auth/authtypes" + "github.com/matrix-org/dendrite/clientapi/auth/storage/accounts" "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/internal/sqlutil" "github.com/matrix-org/gomatrixserverlib" @@ -173,7 +174,7 @@ func (d *Database) createAccount( } if err := d.profiles.insertProfile(ctx, txn, localpart); err != nil { if errors.Is(err, sqlite3.ErrConstraint) { - return nil, internal.ErrUserExists + return nil, accounts.ErrUserExists } return nil, err } diff --git a/clientapi/routing/register.go b/clientapi/routing/register.go index d356db2cb..63f155afd 100644 --- a/clientapi/routing/register.go +++ b/clientapi/routing/register.go @@ -830,7 +830,7 @@ func completeRegistration( acc, err := accountDB.CreateAccount(ctx, username, password, appserviceID) if err != nil { - if errors.Is(err, internal.ErrUserExists) { // user already exists + if errors.Is(err, accounts.ErrUserExists) { // user already exists return util.JSONResponse{ Code: http.StatusBadRequest, JSON: jsonerror.UserInUse("Desired user ID is already taken."), diff --git a/internal/sql.go b/internal/sql.go index b8a706f1d..d6a5a3086 100644 --- a/internal/sql.go +++ b/internal/sql.go @@ -16,15 +16,11 @@ package internal import ( "database/sql" - "errors" "fmt" "runtime" "time" ) -// ErrUserExists is returned if a username already exists in the database. -var ErrUserExists = errors.New("Username already exists") - // A Transaction is something that can be committed or rolledback. type Transaction interface { // Commit the transaction