flipped-aurora/gin-vue-admin · error

岗位 %d 校验失败: %w

Error message

岗位 %d 校验失败: %w

What it means

assign_user_org validates each positionId by calling GET /position/findPosition upstream; any failure (network error, 404/not-found semantics, non-success code) is wrapped as 岗位 %d 校验失败 with the underlying cause. This prevents writing nonexistent position IDs.

Source

Thrown at server/mcp/org_member_assigner.go:117

	}

	// 校验目标部门/岗位真实存在,把无效ID挡在写入之前
	if len(deptIDs) > 0 {
		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)
			}
		}
	}
	for _, id := range positionIDs {
		query := url.Values{}
		query.Set("id", strconv.FormatUint(uint64(id), 10))
		if _, err := getUpstream[system.SysPosition](ctx, "/position/findPosition", query); err != nil {
			return nil, fmt.Errorf("岗位 %d 校验失败: %w", id, err)
		}
	}

	user, err := findUserByID(ctx, userID, usernameHint)
	if err != nil {
		return nil, err
	}

	currentDeptIDs := make([]uint, 0, len(user.Departments))
	for _, dept := range user.Departments {
		currentDeptIDs = append(currentDeptIDs, dept.ID)
	}
	currentPositionIDs := make([]uint, 0, len(user.Positions))
	for _, pos := range user.Positions {
		currentPositionIDs = append(currentPositionIDs, pos.ID)
	}

	result := orgMemberAssignResponse{

View on GitHub (pinned to 3136500ef3)

Solutions

  1. Verify the positionId exists via the admin UI position management page or a position query tool
  2. Check the wrapped cause: if it is a not-found, fix the ID; if network, check upstream connectivity/token
  3. Remove stale position IDs from your automation config
  4. Confirm environment (dev vs prod position IDs)
Defensive patterns

Strategy: validation

Validate before calling

// validate each positionId before the assign call
for (const id of positionIds) {
  const res = await fetch(`${baseUrl}/position/findPosition?id=${id}`)
  const body = await res.json()
  if (!res.ok || body.code !== 0) throw new Error(`position ${id} invalid`)
}

Type guard

function positionResolved(body) {
  return body && body.code === 0 && body.data && body.data.ID > 0
}

Try / catch

try {
  await callMcpTool('assign_user_org', args)
} catch (e) {
  if (/岗位 \d+ 校验失败/.test(e.message)) {
    // parse which id failed and the cause: not-found → fix the ID; network → check upstream/token
  }
}

Prevention

When it happens

Trigger: Calling assign_user_org with a positionId that does not exist (upstream returns not-found) or when the findPosition request itself fails (network, token, upstream 5xx).

Common situations: Deleted or mistyped position IDs; IDs copied from another environment; upstream service unreachable; unlike departments, positions are validated one-by-one so a single bad ID aborts the whole call.

Related errors


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