{"record":{"id":"6d3f144c4fa7f0df","repo":"flipped-aurora/gin-vue-admin","slug":"api-w-6d3f14","errorCode":null,"errorMessage":"获取角色当前API权限失败: %w","messagePattern":"获取角色当前API权限失败: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/mcp/role_api_batch_assigner.go","lineNumber":86,"sourceCode":"\tif err != nil {\n\t\treturn nil, err\n\t}\n\titems, err := parseAPIItems(args[\"apis\"])\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif len(items) == 0 {\n\t\treturn nil, errors.New(\"apis 参数是必需的,且至少包含一条\")\n\t}\n\tif len(items) > orgBatchLimit {\n\t\treturn nil, fmt.Errorf(\"单次批量授权不能超过 %d 条,收到 %d 条\", orgBatchLimit, len(items))\n\t}\n\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\tupdated := currentResp.Data[\"paths\"]\n\tresult := roleAPIBatchAssignResponse{Success: true, AuthorityID: authorityID}\n\tanyAdded := false\n\tfor _, item := range items {\n\t\tvar added bool\n\t\tupdated, added = appendPolicyIfMissing(updated, item.Path, item.Method)\n\t\tpath, method := normalizePolicy(item.Path, item.Method)\n\t\tresult.Items = append(result.Items, batchAPIItemResult{\n\t\t\tPath:          path,\n\t\t\tMethod:        method,\n\t\t\tAdded:         added,\n\t\t\tAlreadyExists: !added,\n\t\t})\n\t\tif added {\n\t\t\tresult.AddedCount++\n\t\t\tanyAdded = true","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/mcp/role_api_batch_assigner.go#L68-L104","documentation":"Same read-phase wrap as error 406 but in the batch assigner: fetching the role's current Casbin policies via /casbin/getPolicyPathByAuthorityId failed, so no diff/merge can be computed and the whole batch aborts.","triggerScenarios":"Batch Handle calls getPolicyPathByAuthorityId before iterating items; failure occurs on network errors, non-2xx responses for an unknown authorityId, expired MCP auth, or payload that fails to decode into map[string][]systemReq.CasbinInfo.","commonSituations":"Typo in role authorityId; role deleted before the call; MCP server cannot reach the admin backend; upstream response format drifted from the expected {paths: [...]} shape.","solutions":["Verify the authorityId exists via a role query tool first","Inspect the wrapped cause for status/body details","Check MCP token validity and casbin read permissions","Retry after confirming backend connectivity"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if authorityID == 0 {\n    return errors.New(\"authorityId is required\")\n}\nif !roleExists(authorityID) {\n    return fmt.Errorf(\"authorityId %d does not exist\", authorityID)\n}\nif len(items) == 0 || len(items) > 50 {\n    return fmt.Errorf(\"apis must contain 1..50 items, got %d\", len(items))\n}","typeGuard":null,"tryCatchPattern":"_, err := batchAssigner.Handle(ctx, args)\nif err != nil {\n    if strings.Contains(err.Error(), \"获取角色当前API权限失败\") {\n        // pre-write read failed; verify role and connectivity, then retry\n    }\n    return err\n}","preventionTips":["Confirm the role exists before any batch assignment","Batch requests are read-modify-write: avoid concurrent batch calls for the same role to prevent lost updates","Keep MCP auth tokens valid; read-phase failures are often 401/403"],"tags":["casbin","upstream-api","batch"],"backgroundTag":"upstream-api-call-failed","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}