flipped-aurora/gin-vue-admin · error
获取角色列表失败: %w
Error message
获取角色列表失败: %w
What it means
fetchAuthority fetches the role tree via POST /authority/getAuthorityList; if that upstream call itself fails, the error is wrapped as 获取角色列表失败. Note this is distinct from the role simply not being found (error 393).
Source
Thrown at server/mcp/org_common.go:183
// findAuthorityInTree 在角色树中按 authorityId 查找角色
func findAuthorityInTree(list []system.SysAuthority, id uint) *system.SysAuthority {
for i := range list {
if list[i].AuthorityId == id {
return &list[i]
}
if found := findAuthorityInTree(list[i].Children, id); found != nil {
return found
}
}
return nil
}
// fetchAuthority 拉取角色树并定位目标角色(getAuthorityList 返回调用者可见的角色树)
func fetchAuthority(ctx context.Context, authorityID uint) (*system.SysAuthority, error) {
resp, err := postUpstream[[]system.SysAuthority](ctx, "/authority/getAuthorityList", map[string]any{})
if err != nil {
return nil, fmt.Errorf("获取角色列表失败: %w", err)
}
authority := findAuthorityInTree(resp.Data, authorityID)
if authority == nil {
return nil, fmt.Errorf("角色 %d 不存在或当前token无权查看", authorityID)
}
return authority, nil
}
// scanUsersByIDs 按ID集合补全用户信息:上游 getUserList 不支持按ID过滤,翻页扫描至集齐或达页数上限,
// 返回 命中映射 与 未解析ID 列表(行级可见范围由主服务侧 datascope 引擎决定)
func scanUsersByIDs(ctx context.Context, ids []uint) (map[uint]system.SysUser, []uint, error) {
want := make(map[uint]struct{}, len(ids))
for _, id := range ids {
want[id] = struct{}{}
}
found := make(map[uint]system.SysUser, len(ids))
for page := 1; page <= orgUserScanMaxPages && len(found) < len(want); page++ {View on GitHub (pinned to 3136500ef3)
Solutions
- Verify the upstream service is reachable and /authority/getAuthorityList returns 200 with code 0
- Refresh/re-issue the upstream token used by the MCP server
- Inspect the wrapped cause in logs to identify transport vs upstream-code failure
- Check for version drift between the MCP tool and the main service API envelope
Defensive patterns
Strategy: try-catch
Validate before calling
// pre-check role tree availability
const res = await fetch(baseUrl + '/authority/getAuthorityList', { method: 'POST' })
if (!res.ok) throw new Error('authority list unavailable') Try / catch
try {
await callMcpTool(tool, args)
} catch (e) {
if (String(e.message).includes('获取角色列表失败')) {
// check connectivity/token, inspect wrapped cause, retry with backoff
}
} Prevention
- Keep the MCP upstream token valid and scoped to see needed roles
- Alert on /authority/getAuthorityList failures
- Differentiate this error from '角色 %d 不存在...' (393) when diagnosing
When it happens
Trigger: Any MCP org tool resolving a role/authority (fetchAuthority via Handle) while POST /authority/getAuthorityList fails at the transport layer or returns a non-success response code: network failure, invalid token, upstream panic/5xx.
Common situations: MCP server cannot reach the main service; token expired; upstream service returning 500; response body not matching the expected envelope so postUpstream decodes it as an error.
Related errors
AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31).
Data as JSON: /api/errors/d1efca532ca1ab81.
Report an issue: GitHub.