fix(user): propagate DB error in CheckEmailExist before existence check#2718
Open
nankingjing wants to merge 1 commit into
Open
fix(user): propagate DB error in CheckEmailExist before existence check#2718nankingjing wants to merge 1 commit into
nankingjing wants to merge 1 commit into
Conversation
CheckEmailExist checked !exist before err, but GetUsersByEmail returns exist=false on a real DB error too. The !exist branch returned (false, nil) first, swallowing the error and making the err!=nil branch dead code. A transient DB error thus made an email look free, so signup (userImpl.Create) proceeded instead of failing. Reorder to return the error first.
Author
Review: fix-checkemailexist-swallow-db-error (#2718)Verdict: LGTM The original code checked Before: GetUsersByEmail fails with DB error, exist=false -> returns (false, nil) -- error swallowed. This is a minimal, correct one-line-adjacent fix. No test included, but the logic is straightforward. Merge-ready. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
backend/domain/user/internal/dal/user.goline 124,UserDAO.CheckEmailExisthas a reversed check order that swallows real DB errors.GetUsersByEmailreturns three cases:(nil, false, nil)(nil, false, err)(user, true, nil)On a real DB error it returns
exist=falseanderr != nil. BecauseCheckEmailExistchecks!existfirst, it returns(false, nil)and never reaches theif err != nilbranch, so that branch is dead code. The transient DB error is silently swallowed and reported as "email does not exist".External consequence
userImpl.Create(backend/domain/user/service/user_impl.go, the signup path) does:When the existence query hits a transient DB error,
CheckEmailExistreturns(false, nil), soCreatetreats the email as free and proceeds to CreateUser instead of aborting with the error. This masks the failure and leads to a wrong signup outcome (duplicate-account attempt / unique-constraint failure on insert) instead of a clean, retryable error.Fix
Return the error before the existence check, so real DB errors propagate while the not-found and found cases keep their exact prior behavior:
Behavior table (unchanged for correct cases, fixed for the error case):
(false, nil)(false, nil)(false, nil)swallowed(false, err)propagated(true, nil)(true, nil)The
(bool, error)contract is preserved. Minimal, focused diff (statement reorder only).Verification
No Go toolchain in the environment (
go: command not found), so verified by reading and tracing the two functions and the caller; not executed.