flipped-aurora/gin-vue-admin · error

读取角色当前自定义部门集失败: %w

Error message

读取角色当前自定义部门集失败: %w

What it means

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.

Source

Thrown at server/mcp/role_data_scope_setter.go:121

			return nil, err
		}
		for _, id := range deptIDs {
			if _, ok := deptIndex[id]; !ok {
				return nil, fmt.Errorf("部门 %d 不存在,可先用 query_org_structure 查询部门树", id)
			}
		}
	}

	// 读取变更前状态:角色档位来自角色树,自定义部门集来自专用接口
	authority, err := fetchAuthority(ctx, authorityID)
	if err != nil {
		return nil, err
	}
	query := url.Values{}
	query.Set("authorityId", strconv.FormatUint(uint64(authorityID), 10))
	beforeDeptsResp, err := getUpstream[[]uint](ctx, "/authority/getDataScopeDepts", query)
	if err != nil {
		return nil, fmt.Errorf("读取角色当前自定义部门集失败: %w", err)
	}

	before := dataScopeState{
		DataScope: authority.DataScope,
		Label:     dataScopeLabels[authority.DataScope],
		DeptIDs:   beforeDeptsResp.Data,
	}

	if _, err := postUpstream[map[string]any](ctx, "/authority/setDataScope", map[string]any{
		"authorityId": authorityID,
		"dataScope":   scope,
		"deptIds":     deptIDs,
	}); err != nil {
		return nil, fmt.Errorf("设置数据权限失败: %w", err)
	}

	after := dataScopeState{
		DataScope: scope,

View on GitHub (pinned to 3136500ef3)

Solutions

  1. Check the wrapped error: a 404 means the gva server version lacks the endpoint — upgrade the server
  2. Refresh authentication if the error indicates 401/403
  3. Verify network connectivity to the upstream gva host
  4. Retry the operation once connectivity/auth is restored

Example fix

// before
beforeDeptsResp, err := getUpstream[[]uint](ctx, "/authority/getDataScopeDepts", query)
// after
if err != nil {
    log.Printf("getDataScopeDepts failed (authorityId=%d): %v", authorityID, err)
    return nil, fmt.Errorf("读取角色当前自定义部门集失败: %w", err)
}
Defensive patterns

Strategy: retry

Validate before calling

// ensure auth is valid before the read
if !tokenFresh(mcpToken) {
    refreshToken()
}

Try / catch

before, err := readCurrentDepts(ctx, authorityID)
if err != nil {
    if isAuthError(err) {
        refreshToken()
        before, err = readCurrentDepts(ctx, authorityID)
    }
    if err != nil {
        return err
    }
}

Prevention

When it happens

Trigger: Upstream GET /authority/getDataScopeDepts fails due to network issues, 401/403 auth, or the endpoint being unavailable in an older gva server version.

Common situations: Expired JWT; older server build lacking the getDataScopeDepts route (404); temporary network partition between MCP server and gva backend.

Related errors


AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31). Data as JSON: /api/errors/5449cdd4e63c961a. Report an issue: GitHub.