chenhg5/cc-connect · error

platform index %d out of range: project %q has %d weixin pla

Error message

platform index %d out of range: project %q has %d weixin platform(s)

What it means

Weixin platforms are selected by a 1-based index among the project's weixin-typed platforms only. opts.PlatformIndex is converted to a 0-based position; if that position falls outside the collected weixin candidate list, this error reports the requested index and how many weixin platforms exist.

Source

Thrown at config/config.go:2441

	proj := &cfg.Projects[projectIdx]
	candidates := make([]int, 0, len(proj.Platforms))
	for i := range proj.Platforms {
		t := strings.ToLower(strings.TrimSpace(proj.Platforms[i].Type))
		if t == "weixin" {
			candidates = append(candidates, i)
		}
	}
	if len(candidates) == 0 {
		return nil, fmt.Errorf("project %q has no weixin platform", opts.ProjectName)
	}

	targetPos := 0
	if opts.PlatformIndex > 0 {
		targetPos = opts.PlatformIndex - 1
	}
	if targetPos < 0 || targetPos >= len(candidates) {
		return nil, fmt.Errorf(
			"platform index %d out of range: project %q has %d weixin platform(s)",
			opts.PlatformIndex, opts.ProjectName, len(candidates),
		)
	}

	absIdx := candidates[targetPos]
	platform := &proj.Platforms[absIdx]
	if platform.Options == nil {
		platform.Options = map[string]any{}
	}

	token := strings.TrimSpace(opts.Token)
	platform.Options["token"] = token

	if u := strings.TrimSpace(opts.BaseURL); u != "" {
		platform.Options["base_url"] = u
	}
	if u := strings.TrimSpace(opts.CDNBaseURL); u != "" {

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Set opts.PlatformIndex to a value between 1 and the number of weixin platforms in the project
  2. Omit PlatformIndex (or pass 0) to target the first weixin platform
  3. Count the [[projects.platforms]] blocks with type = "weixin" under the project to get the valid range

Example fix

// before
opts.PlatformIndex = 3 // project only has 1 weixin platform
// after
opts.PlatformIndex = 1
Defensive patterns

Strategy: validation

Validate before calling

var weixinCount int
for _, pl := range proj.Platforms {
    if strings.ToLower(strings.TrimSpace(pl.Type)) == "weixin" { weixinCount++ }
}
if opts.PlatformIndex < 0 || opts.PlatformIndex > weixinCount {
    return fmt.Errorf("PlatformIndex must be 1..%d", weixinCount)
}

Prevention

When it happens

Trigger: Calling SaveWeixinPlatformCredentials with opts.PlatformIndex = N where N-1 >= number of platforms with type "weixin" in that project (e.g. PlatformIndex=2 with only one weixin platform), or PlatformIndex=0 semantics aside, any index beyond the candidate count.

Common situations: User assumed the index counts all platforms in the project (including non-weixin ones), stale UI/scripts referencing an old platform that was removed from config.toml, or copy-pasting an index from a different project.

Related errors


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/410a268bfbd4c23c. Report an issue: GitHub.