{"record":{"id":"86b583ab84ced302","repo":"flipped-aurora/gin-vue-admin","slug":"api-w","errorCode":null,"errorMessage":"获取角色当前API权限失败: %w","messagePattern":"获取角色当前API权限失败: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/mcp/role_api_assigner.go","lineNumber":79,"sourceCode":"\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tpath, ok := args[\"path\"].(string)\n\tif !ok || strings.TrimSpace(path) == \"\" {\n\t\treturn nil, errors.New(\"path 参数是必需的\")\n\t}\n\tmethod := \"POST\"\n\tif value, ok := args[\"method\"].(string); ok && strings.TrimSpace(value) != \"\" {\n\t\tmethod = value\n\t}\n\n\tpath, method = normalizePolicy(path, method)\n\tcurrentResp, err := postUpstream[map[string][]systemReq.CasbinInfo](ctx, \"/casbin/getPolicyPathByAuthorityId\", map[string]any{\n\t\t\"authorityId\": authorityID,\n\t})\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"获取角色当前API权限失败: %w\", err)\n\t}\n\n\tcurrent := currentResp.Data[\"paths\"]\n\tupdated, added := appendPolicyIfMissing(current, path, method)\n\tif added {\n\t\tif _, err = postUpstream[map[string]any](ctx, \"/casbin/updateCasbin\", map[string]any{\n\t\t\t\"authorityId\": authorityID,\n\t\t\t\"casbinInfos\": updated,\n\t\t}); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"分配API权限失败: %w\", err)\n\t\t}\n\t}\n\n\tmsg := \"权限已存在，无需重复分配\"\n\tif added {\n\t\tmsg = fmt.Sprintf(\"成功为角色 %d 分配权限 %s %s\", authorityID, method, path)\n\t}\n","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/mcp/role_api_assigner.go#L61-L97","documentation":"Wrap of an upstream error when fetching the role's current Casbin API policies via POST /casbin/getPolicyPathByAuthorityId. The assigner needs the current policy list to compute the diff before updating; failing this read aborts the assignment.","triggerScenarios":"Handle calls getPolicyPathByAuthorityId for the given authorityId and postUpstream fails — network error, non-2xx response, unknown/nonexistent authorityId rejected by the backend, or decode failure into map[string][]systemReq.CasbinInfo.","commonSituations":"Role (authorityId) does not exist or was deleted; MCP token lacks casbin read permission; backend temporarily down; response schema changed so Data[\"paths\"] no longer decodes.","solutions":["Verify the authorityId corresponds to an existing role (query roles first)","Check the wrapped cause for the upstream status/body","Confirm MCP credentials can access the casbin endpoints","Retry when the backend is confirmed healthy"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"roles, err := client.ListRoles(ctx)\nif err != nil { return err }\nexists := false\nfor _, r := range roles {\n    if uint(r.ID) == authorityID { exists = true; break }\n}\nif !exists {\n    return fmt.Errorf(\"authorityId %d does not exist\", authorityID)\n}","typeGuard":null,"tryCatchPattern":"_, err := assigner.Handle(ctx, args)\nif err != nil {\n    if strings.Contains(err.Error(), \"获取角色当前API权限失败\") {\n        // read-phase failure: check role exists, token perms, backend health\n        // retry only on network/5xx causes\n    }\n    return err\n}","preventionTips":["Resolve authorityId from a live role list, never from memory","Ensure MCP credentials include casbin read scope","Health-check the backend before permission-editing sessions"],"tags":["casbin","upstream-api","roles"],"backgroundTag":"upstream-api-call-failed","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}