{"record":{"id":"d59021c4c246d275","repo":"flipped-aurora/gin-vue-admin","slug":"error-d59021","errorCode":null,"errorMessage":"用户不存在","messagePattern":"用户不存在","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/service/system/sys_user.go","lineNumber":403,"sourceCode":"//@param: id int\n//@return: err error, user *model.SysUser\n\nfunc (userService *UserService) FindUserById(ctx context.Context, id int) (user *system.SysUser, err error) {\n\tvar u system.SysUser\n\terr = global.GVA_DB.WithContext(ctx).Where(\"id = ?\", id).First(&u).Error\n\treturn &u, err\n}\n\n//@author: [SliverHorn](https://github.com/SliverHorn)\n//@function: FindUserByUuid\n//@description: 通过uuid获取用户信息\n//@param: uuid string\n//@return: err error, user *model.SysUser\n\nfunc (userService *UserService) FindUserByUuid(ctx context.Context, uuid string) (user *system.SysUser, err error) {\n\tvar u system.SysUser\n\tif err = global.GVA_DB.WithContext(ctx).Where(\"uuid = ?\", uuid).First(&u).Error; err != nil {\n\t\treturn &u, errors.New(\"用户不存在\")\n\t}\n\treturn &u, nil\n}\n\n//@author: [piexlmax](https://github.com/piexlmax)\n//@function: ResetPassword\n//@description: 修改用户密码\n//@param: ID uint\n//@return: err error\n\nfunc (userService *UserService) ResetPassword(ctx context.Context, ID uint, password string) (err error) {\n\tnow := time.Now()\n\terr = global.GVA_DB.WithContext(ctx).Model(&system.SysUser{}).Where(\"id = ?\", ID).Updates(map[string]interface{}{\n\t\t\"password\":            utils.BcryptHash(password),\n\t\t\"password_updated_at\": now,\n\t}).Error\n\treturn err\n}","sourceCodeStart":385,"sourceCodeEnd":421,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/service/system/sys_user.go#L385-L421","documentation":"FindUserByUuid looks up a SysUser by its uuid column; when First(&u) returns an error (typically gorm.ErrRecordNotFound), it discards the cause and returns errors.New(\"用户不存在\") along with an empty user. It converts any DB-level failure into the domain message 'user does not exist'.","triggerScenarios":"Calling FindUserByUuid (sys_user.go:403) with a uuid that has no row in sys_user — expired/garbage token uuids, users deleted after a token was issued, or a malformed uuid string.","commonSituations":"JWT contains a uuid for a user deleted or re-created (new uuid) since issuance; stale cached user records in the front end; tokens issued before a database reset.","solutions":["Re-login to obtain a fresh token with a valid uuid if the user was deleted/recreated.","Verify the uuid string passed matches the sys_user.uuid column value exactly.","Check the DB for the uuid: SELECT * FROM sys_user WHERE uuid = ? to confirm existence.","If this follows a DB restore/reset, re-issue tokens for all users."],"exampleFix":"// before\nuser, err := userService.FindUserByUuid(ctx, oldTokenUuid) // user recreated, uuid changed\n// after\nclaims := utils.GetClaims(c) // read uuid from current valid token\nuser, err := userService.FindUserByUuid(ctx, claims.UUID)","handlingStrategy":"try-catch","validationCode":"if (!uuid || uuid.length < 16) { throw new Error('无效的用户标识') }","typeGuard":null,"tryCatchPattern":"user, err := userService.FindUserByUuid(ctx, uuid)\nif err != nil {\n  // treat as unauthenticated; force re-login\n  response.FailWithMessage(\"登录状态失效，请重新登录\", c)\n  return\n}","preventionTips":["Force re-login when a token's uuid no longer resolves to a user.","Invalidate tokens on user deletion/recreation.","Log the underlying DB error to distinguish not-found from connection issues."],"tags":["auth","uuid","user","not-found"],"backgroundTag":"user-not-found-by-uuid","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}