{"record":{"id":"ad1370b19ab55b32","repo":"flipped-aurora/gin-vue-admin","slug":"5-w","errorCode":null,"errorMessage":"档位5(自定义部门)必须指定部门集合: %w","messagePattern":"档位5\\(自定义部门\\)必须指定部门集合: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/mcp/role_data_scope_setter.go","lineNumber":99,"sourceCode":"\t}\n\n\tdataScope, err := parseUintParam(args[\"dataScope\"], \"dataScope\")\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif dataScope < 1 || dataScope > 5 {\n\t\treturn nil, fmt.Errorf(\"dataScope 必须在 1-5 之间：1全部 2本部门及以下 3本部门 4仅本人 5自定义部门，收到 %d\", dataScope)\n\t}\n\tscope := int(dataScope)\n\n\tvar deptIDs []uint\n\tif scope == 5 {\n\t\tdeptIDs, err = parseUintList(args[\"deptIds\"], \"deptIds\")\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tif err := requireNonEmptyList(deptIDs, \"deptIds\"); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"档位5(自定义部门)必须指定部门集合: %w\", err)\n\t\t}\n\t\tdeptIndex, err := fetchDeptIndex(ctx)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tfor _, id := range deptIDs {\n\t\t\tif _, ok := deptIndex[id]; !ok {\n\t\t\t\treturn nil, fmt.Errorf(\"部门 %d 不存在,可先用 query_org_structure 查询部门树\", id)\n\t\t\t}\n\t\t}\n\t}\n\n\t// 读取变更前状态:角色档位来自角色树,自定义部门集来自专用接口\n\tauthority, err := fetchAuthority(ctx, authorityID)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tquery := url.Values{}","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/mcp/role_data_scope_setter.go#L81-L117","documentation":"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.","triggerScenarios":"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).","commonSituations":"UI forgot to collect selected departments before submit; caller assumed deptIds optional for tier 5; serialization dropped an empty array field.","solutions":["Provide a non-empty deptIds array together with dataScope=5","Validate the department list length > 0 before calling the tool","If the intent is not a custom scope, choose tier 1-4 instead and omit deptIds"],"exampleFix":"// before\nargs := map[string]any{\"dataScope\": 5, \"deptIds\": []uint{}}\n// after\nargs := map[string]any{\"dataScope\": 5, \"deptIds\": []uint{2, 7}}","handlingStrategy":"validation","validationCode":"if dataScope == 5 && len(deptIds) == 0 {\n    return fmt.Errorf(\"deptIds is required and non-empty when dataScope == 5\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pair dataScope=5 with a populated deptIds list","Check array length after deserialization (empty arrays can be dropped)","Choose tier 1-4 if no custom departments are needed"],"tags":["mcp","validation","data-scope"],"backgroundTag":"missing-required-parameter","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}