{"record":{"id":"5449cdd4e63c961a","repo":"flipped-aurora/gin-vue-admin","slug":"w-5449cd","errorCode":null,"errorMessage":"读取角色当前自定义部门集失败: %w","messagePattern":"读取角色当前自定义部门集失败: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/mcp/role_data_scope_setter.go","lineNumber":121,"sourceCode":"\t\t\treturn nil, err\n\t\t}\n\t\tfor _, id := range deptIDs {\n\t\t\tif _, ok := deptIndex[id]; !ok {\n\t\t\t\treturn nil, fmt.Errorf(\"部门 %d 不存在,可先用 query_org_structure 查询部门树\", id)\n\t\t\t}\n\t\t}\n\t}\n\n\t// 读取变更前状态:角色档位来自角色树,自定义部门集来自专用接口\n\tauthority, err := fetchAuthority(ctx, authorityID)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tquery := url.Values{}\n\tquery.Set(\"authorityId\", strconv.FormatUint(uint64(authorityID), 10))\n\tbeforeDeptsResp, err := getUpstream[[]uint](ctx, \"/authority/getDataScopeDepts\", query)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"读取角色当前自定义部门集失败: %w\", err)\n\t}\n\n\tbefore := dataScopeState{\n\t\tDataScope: authority.DataScope,\n\t\tLabel:     dataScopeLabels[authority.DataScope],\n\t\tDeptIDs:   beforeDeptsResp.Data,\n\t}\n\n\tif _, err := postUpstream[map[string]any](ctx, \"/authority/setDataScope\", map[string]any{\n\t\t\"authorityId\": authorityID,\n\t\t\"dataScope\":   scope,\n\t\t\"deptIds\":     deptIDs,\n\t}); err != nil {\n\t\treturn nil, fmt.Errorf(\"设置数据权限失败: %w\", err)\n\t}\n\n\tafter := dataScopeState{\n\t\tDataScope: scope,","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/mcp/role_data_scope_setter.go#L103-L139","documentation":"Before applying a new data scope, the setter reads the role's current custom department set from `/authority/getDataScopeDepts` to build a before/after diff. Failure of that GET (wrapped with %w) aborts the operation so the change report stays accurate. The root cause is preserved in the wrapped error.","triggerScenarios":"Upstream GET /authority/getDataScopeDepts fails due to network issues, 401/403 auth, or the endpoint being unavailable in an older gva server version.","commonSituations":"Expired JWT; older server build lacking the getDataScopeDepts route (404); temporary network partition between MCP server and gva backend.","solutions":["Check the wrapped error: a 404 means the gva server version lacks the endpoint — upgrade the server","Refresh authentication if the error indicates 401/403","Verify network connectivity to the upstream gva host","Retry the operation once connectivity/auth is restored"],"exampleFix":"// before\nbeforeDeptsResp, err := getUpstream[[]uint](ctx, \"/authority/getDataScopeDepts\", query)\n// after\nif err != nil {\n    log.Printf(\"getDataScopeDepts failed (authorityId=%d): %v\", authorityID, err)\n    return nil, fmt.Errorf(\"读取角色当前自定义部门集失败: %w\", err)\n}","handlingStrategy":"retry","validationCode":"// ensure auth is valid before the read\nif !tokenFresh(mcpToken) {\n    refreshToken()\n}","typeGuard":null,"tryCatchPattern":"before, err := readCurrentDepts(ctx, authorityID)\nif err != nil {\n    if isAuthError(err) {\n        refreshToken()\n        before, err = readCurrentDepts(ctx, authorityID)\n    }\n    if err != nil {\n        return err\n    }\n}","preventionTips":["Keep the upstream token refreshed","Confirm server version supports /authority/getDataScopeDepts","Monitor connectivity between MCP server and gva backend"],"tags":["mcp","upstream-api","network"],"backgroundTag":"upstream-request-failed","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}