{"record":{"id":"52238007eb81a688","repo":"flipped-aurora/gin-vue-admin","slug":"error-522380","errorCode":null,"errorMessage":"查询角色数据失败","messagePattern":"查询角色数据失败","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/service/system/sys_authority.go","lineNumber":122,"sourceCode":"\terr = CasbinServiceApp.UpdateCasbin(ctx, adminAuthorityID, copyInfo.Authority.AuthorityId, paths)\n\tif err != nil {\n\t\t_ = authorityService.DeleteAuthority(ctx, &copyInfo.Authority)\n\t}\n\treturn copyInfo.Authority, err\n}\n\n//@author: [piexlmax](https://github.com/piexlmax)\n//@function: UpdateAuthority\n//@description: 更改一个角色\n//@param: auth model.SysAuthority\n//@return: authority system.SysAuthority, err error\n\nfunc (authorityService *AuthorityService) UpdateAuthority(ctx context.Context, auth system.SysAuthority) (authority system.SysAuthority, err error) {\n\tvar oldAuthority system.SysAuthority\n\terr = global.GVA_DB.WithContext(ctx).Where(\"authority_id = ?\", auth.AuthorityId).First(&oldAuthority).Error\n\tif err != nil {\n\t\tlogger.WithCtx(ctx).Mod(\"biz\").Debug(err.Error())\n\t\treturn system.SysAuthority{}, errors.New(\"查询角色数据失败\")\n\t}\n\terr = global.GVA_DB.WithContext(ctx).Model(&oldAuthority).Updates(&auth).Error\n\treturn auth, err\n}\n\n//@author: [piexlmax](https://github.com/piexlmax)\n//@function: DeleteAuthority\n//@description: 删除角色\n//@param: auth *model.SysAuthority\n//@return: err error\n\nfunc (authorityService *AuthorityService) DeleteAuthority(ctx context.Context, auth *system.SysAuthority) error {\n\tif errors.Is(global.GVA_DB.WithContext(ctx).Preload(\"Users\").First(&auth).Error, gorm.ErrRecordNotFound) {\n\t\treturn errors.New(\"该角色不存在\")\n\t}\n\tif len(auth.Users) != 0 {\n\t\treturn errors.New(\"此角色有用户正在使用禁止删除\")\n\t}","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/service/system/sys_authority.go#L104-L140","documentation":"UpdateAuthority first loads the existing role by authority_id before applying Updates. If that First() query fails (role missing, or any DB error), it logs the underlying error at debug level and returns the generic \"查询角色数据失败\" to the caller. Note this masks the real cause — including transient DB failures — behind one message.","triggerScenarios":"Calling PUT /authority/updateAuthority with an authorityId not present in sys_authorities; or the underlying SELECT fails due to DB connectivity/schema issues.","commonSituations":"Frontend holds a stale role list after the role was deleted in another tab/user; ID type mismatch in the payload; database down or table missing after a partial migration.","solutions":["Confirm the role still exists (role management page or SELECT from sys_authorities) and use a valid authorityId.","Refresh the frontend role list to clear stale IDs, then retry.","Check server logs — the real gorm error is logged at debug level (logger.WithCtx(ctx).Mod(\"biz\").Debug) before the generic message is returned."],"exampleFix":"// before\nupdateAuthority({ authorityId: 7777, authorityName: 'ops' }) // 7777 was deleted\n\n// after: re-fetch then update\nconst roles = await getAuthorityList()\nconst target = roles.data.list.find(r => r.authorityName === 'ops')\nawait updateAuthority({ authorityId: target.authorityId, authorityName: 'ops' })","handlingStrategy":"try-catch","validationCode":"const roles = (await getAuthorityList()).data.list\nif (!roles.some(r => r.authorityId === form.authorityId)) throw new Error('角色 ' + form.authorityId + ' 不存在，无法更新')","typeGuard":null,"tryCatchPattern":"try {\n  await updateAuthority(form)\n} catch (e) {\n  if (String(e?.msg).includes('查询角色数据失败')) {\n    logger.debug('underlying gorm error', e)\n    ElMessage.error('角色不存在或查询失败：请刷新角色列表后重试')\n  } else { throw e }\n}","preventionTips":["Refresh the role list before updates so payloads don't carry deleted IDs.","Remember this error masks the real DB error — check server debug logs for the underlying cause.","Handle concurrent deletions: re-fetch the role before editing in long-lived forms.","Monitor DB connectivity/schema health if this error appears for IDs you know exist."],"tags":["role","record-not-found","gorm","error-masking"],"backgroundTag":"record-not-found","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}