From cc3c18be4f50a0d84e6557ee5e58915125dbbf7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A0=95=ED=95=B8=EB=AA=A8?= Date: Sun, 21 Jul 2024 08:57:10 +0900 Subject: [PATCH] Update coderabbitai's review --- server/backend/database/memory/database.go | 10 ++++++++-- server/users/users.go | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/server/backend/database/memory/database.go b/server/backend/database/memory/database.go index 2ffe7354b..77794d008 100644 --- a/server/backend/database/memory/database.go +++ b/server/backend/database/memory/database.go @@ -633,9 +633,12 @@ func (d *DB) DeleteUserInfoByName(_ context.Context, username string) error { defer txn.Abort() raw, err := txn.First(tblUsers, "username", username) - if err != nil || raw == nil { + if err != nil { return fmt.Errorf("find user by username: %w", err) } + if raw == nil { + return fmt.Errorf("%s: %w", username, database.ErrUserNotFound) + } info := raw.(*database.UserInfo).DeepCopy() if err = txn.Delete(tblUsers, info); err != nil { @@ -652,9 +655,12 @@ func (d *DB) ChangePassword(_ context.Context, username, hashedNewPassword strin defer txn.Abort() raw, err := txn.First(tblUsers, "username", username) - if err != nil || raw == nil { + if err != nil { return fmt.Errorf("find user by username: %w", err) } + if raw == nil { + return fmt.Errorf("%s: %w", username, database.ErrUserNotFound) + } info := raw.(*database.UserInfo).DeepCopy() info.HashedPassword = hashedNewPassword diff --git a/server/users/users.go b/server/users/users.go index 58f11ddc9..98f2661da 100644 --- a/server/users/users.go +++ b/server/users/users.go @@ -108,7 +108,7 @@ func DeleteAccountByName( return nil } -// ChangePassword deletes a user by name. +// ChangePassword changes the password for a user. func ChangePassword( ctx context.Context, be *backend.Backend,