{"record":{"id":"d3893a27c96a3ef3","repo":"plandex-ai/plandex","slug":"error-getting-user-v","errorCode":null,"errorMessage":"error getting user: %v","messagePattern":"error getting user: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/server/handlers/auth_helpers.go","lineNumber":314,"sourceCode":"\tvar signInCodeId string\n\tvar signInCodeOrgId string\n\tvar err error\n\n\tisLocalMode := (os.Getenv(\"GOENV\") == \"development\" && os.Getenv(\"LOCAL_MODE\") == \"1\")\n\n\tif req.IsSignInCode {\n\t\tres, err := db.ValidateSignInCode(req.Pin)\n\n\t\tif err != nil {\n\t\t\tlog.Printf(\"Error validating sign in code: %v\\n\", err)\n\t\t\treturn nil, fmt.Errorf(\"error validating sign in code: %v\", err)\n\t\t}\n\n\t\tuser, err = db.GetUser(res.UserId)\n\n\t\tif err != nil {\n\t\t\tlog.Printf(\"Error getting user: %v\\n\", err)\n\t\t\treturn nil, fmt.Errorf(\"error getting user: %v\", err)\n\t\t}\n\n\t\tif user == nil {\n\t\t\tlog.Printf(\"User not found for id: %v\\n\", res.UserId)\n\t\t\treturn nil, fmt.Errorf(\"user not found\")\n\t\t}\n\n\t\tsignInCodeId = res.Id\n\t\tsignInCodeOrgId = res.OrgId\n\t} else {\n\t\treq.Email = strings.ToLower(req.Email)\n\t\tuser, err = db.GetUserByEmail(req.Email)\n\n\t\tif err != nil {\n\t\t\tlog.Printf(\"Error getting user: %v\\n\", err)\n\t\t\treturn nil, fmt.Errorf(\"error getting user: %v\", err)\n\t\t}\n","sourceCodeStart":296,"sourceCodeEnd":332,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/handlers/auth_helpers.go#L296-L332","documentation":"ValidateAndSignIn wraps a failure from db.GetUser(res.UserId) after a successful sign-in-code redemption. It means the user record backing the redeemed sign-in code could not be loaded from the database (or the store returned an error). The raw DB error is preserved via %v for diagnostics.","triggerScenarios":"A client signs in with a sign-in code / codeId+pin flow; ValidateCode succeeds and returns res.UserId, but the subsequent db.GetUser(res.UserId) returns a non-nil error (DB connectivity failure, query timeout, row decode error).","commonSituations":"Database down or restarted mid-request; stale/corrupt sign-in code pointing at a deleted user row via foreign-key mismatch; connection pool exhaustion under load; migration drift causing GetUser query failures.","solutions":["Check the wrapped %v cause for the real DB error (connection refused, timeout, no rows)","Verify DB connectivity/credentials in server config","Confirm the sign-in code's user row exists and was not soft/hard deleted","Inspect db.GetUser logs near this error in server logs for the underlying query failure"],"exampleFix":"// before\nif err != nil {\n\treturn nil, fmt.Errorf(\"error getting user: %v\", err)\n}\n// after\nif err != nil {\n\tlog.Printf(\"GetUser failed for id=%v: %v\", res.UserId, err)\n\treturn nil, fmt.Errorf(\"error getting user: %v\", err)\n}","handlingStrategy":"try-catch","validationCode":"// Go has no pre-call validation; check DB health first\nif err := db.Ping(); err != nil {\n\treturn fmt.Errorf(\"database unavailable: %v\", err)\n}","typeGuard":"func userExists(id string) bool {\n\tu, err := db.GetUser(id)\n\treturn err == nil && u != nil\n}","tryCatchPattern":"user, err := ValidateAndSignIn(w, r, req)\nif err != nil {\n\tif strings.HasPrefix(err.Error(), \"error getting user\") {\n\t\t// transient DB issue: log cause and return 503\n\t\thttp.Error(w, \"database error, try again\", http.StatusServiceUnavailable)\n\t\treturn\n\t}\n\thttp.Error(w, err.Error(), http.StatusUnauthorized)\n}","preventionTips":["Monitor DB connectivity and pool saturation","Alert on orphaned sign-in codes pointing at deleted users","Log the wrapped cause alongside the generic message","Retry transient DB errors with backoff in GetUser callers"],"tags":["database","auth","signin"],"backgroundTag":"user-lookup-failed","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}