flipped-aurora/gin-vue-admin · error

档位5(自定义部门)必须指定部门集合: %w

Error message

档位5(自定义部门)必须指定部门集合: %w

What it means

When dataScope is 5 (custom departments), the setter requires a non-empty `deptIds` list. If the list is missing or empty after parsing, the error wraps the requireNonEmptyList failure. Tier 5 without a department set would leave the role with an unusable empty scope, so it is rejected up front.

Source

Thrown at server/mcp/role_data_scope_setter.go:99

	}

	dataScope, err := parseUintParam(args["dataScope"], "dataScope")
	if err != nil {
		return nil, err
	}
	if dataScope < 1 || dataScope > 5 {
		return nil, fmt.Errorf("dataScope 必须在 1-5 之间:1全部 2本部门及以下 3本部门 4仅本人 5自定义部门,收到 %d", dataScope)
	}
	scope := int(dataScope)

	var deptIDs []uint
	if scope == 5 {
		deptIDs, err = parseUintList(args["deptIds"], "deptIds")
		if err != nil {
			return nil, err
		}
		if err := requireNonEmptyList(deptIDs, "deptIds"); err != nil {
			return nil, fmt.Errorf("档位5(自定义部门)必须指定部门集合: %w", err)
		}
		deptIndex, err := fetchDeptIndex(ctx)
		if err != nil {
			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{}

View on GitHub (pinned to 3136500ef3)

Solutions

  1. Provide a non-empty deptIds array together with dataScope=5
  2. Validate the department list length > 0 before calling the tool
  3. If the intent is not a custom scope, choose tier 1-4 instead and omit deptIds

Example fix

// before
args := map[string]any{"dataScope": 5, "deptIds": []uint{}}
// after
args := map[string]any{"dataScope": 5, "deptIds": []uint{2, 7}}
Defensive patterns

Strategy: validation

Validate before calling

if dataScope == 5 && len(deptIds) == 0 {
    return fmt.Errorf("deptIds is required and non-empty when dataScope == 5")
}

Prevention

When it happens

Trigger: Calling set-data-scope with dataScope=5 but omitting deptIds, passing an empty array, or passing a value that parses to zero items (e.g. empty string).

Common situations: UI forgot to collect selected departments before submit; caller assumed deptIds optional for tier 5; serialization dropped an empty array field.

Understand the failure class

Background: Missing required parameter errors: what 'X is required' and 'the required X param is missing' mean, and how to fix them — this error's family across 27 libraries.

Related errors


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