flipped-aurora/gin-vue-admin · error

设置用户岗位失败: %w

Error message

设置用户岗位失败: %w

What it means

Wrap of an upstream HTTP error from POST /user/setUserPositions while assigning positions to a member. The tool computed the merged position set but the write to the backend failed; the root cause is preserved with %w.

Source

Thrown at server/mcp/org_member_assigner.go:185

		} else {
			messages = append(messages, "部门均已存在,未写入")
		}
		result.Departments = &orgAssignChange{Before: currentDeptIDs, After: merged, Added: added}
		// 上游对 primaryDeptId=0 取部门集合首个;如实回报生效主部门,不因 0 值被 omitempty 隐去而误导
		result.PrimaryDeptID = primary
		if primary == 0 && len(merged) > 0 {
			result.PrimaryDeptID = merged[0]
		}
	}

	if len(positionIDs) > 0 {
		merged, added := mergeUintSets(currentPositionIDs, positionIDs)
		if len(added) > 0 {
			if _, err := postUpstream[map[string]any](ctx, "/user/setUserPositions", map[string]any{
				"ID":          user.ID,
				"positionIds": merged,
			}); err != nil {
				return nil, fmt.Errorf("设置用户岗位失败: %w", err)
			}
			messages = append(messages, fmt.Sprintf("岗位新增 %v", added))
		} else {
			messages = append(messages, "岗位均已存在,未写入")
		}
		result.Positions = &orgAssignChange{Before: currentPositionIDs, After: merged, Added: added}
	}

	result.AlreadyExists = (result.Departments == nil || len(result.Departments.Added) == 0) &&
		(result.Positions == nil || len(result.Positions.Added) == 0)
	result.Message = fmt.Sprintf("用户 %s(ID:%d) 组织归属分配完成:%s", user.Username, user.ID, strings.Join(messages, ";"))

	return textResultWithJSON("用户组织归属分配结果:", result)
}

View on GitHub (pinned to 3136500ef3)

Solutions

  1. Inspect the wrapped cause for the upstream status/body
  2. Validate the positionIds exist via the org query tool before assigning
  3. Verify MCP credentials/permissions for /user/setUserPositions
  4. Retry once the backend service is confirmed healthy
Defensive patterns

Strategy: try-catch

Validate before calling

for _, pid := range positionIDs {
    if !knownPositionIDs[pid] {
        return fmt.Errorf("position %d does not exist", pid)
    }
}

Try / catch

res, err := assigner.Handle(ctx, args)
if err != nil {
    if strings.Contains(err.Error(), "设置用户岗位失败") {
        // unwrap and decide: retry on 5xx/network, abort on 4xx validation
    }
    return err
}

Prevention

When it happens

Trigger: Handle calls postUpstream to /user/setUserPositions with the merged positionIds and the upstream returns an error (network, auth, invalid position ID, deleted user).

Common situations: Position IDs from a stale list (position deleted); MCP token expired; backend API validation rejecting an unknown positionId; transient network blip.

Related errors


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