chenhg5/cc-connect · error
platform index %d out of range: project %q has %d yuanbao pl
Error message
platform index %d out of range: project %q has %d yuanbao platform(s)
What it means
Returned when opts.PlatformIndex, converted to a 0-based position (PlatformIndex - 1 for values > 0), is >= the number of yuanbao platforms found in the project. The error message reports the requested index, the project name, and how many yuanbao platforms actually exist, making it self-diagnosing.
Source
Thrown at config/config.go:2751
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 == "yuanbao" {
candidates = append(candidates, i)
}
}
if len(candidates) == 0 {
return nil, fmt.Errorf("project %q has no yuanbao 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 yuanbao platform(s)",
opts.PlatformIndex, opts.ProjectName, len(candidates),
)
}
absIdx := candidates[targetPos]
platform := &proj.Platforms[absIdx]
if platform.Options == nil {
platform.Options = map[string]any{}
}
platform.Options["bot_token"] = botToken
allowFrom := strings.TrimSpace(stringOption(platform.Options["allow_from"]))
if v := strings.TrimSpace(opts.AllowFrom); v != "" {
allowFrom = v
platform.Options["allow_from"] = v
}View on GitHub (pinned to 4000b2338a)
Solutions
- Set PlatformIndex to a value between 0 (default/first) and the number of yuanbao platforms in the project (inclusive of count for 1-based)
- Count existing yuanbao platforms in the project's [[projects.platforms]] blocks and pick a valid index (the message tells you the count)
- Refresh any persisted index after platform add/remove operations
Example fix
// before opts.PlatformIndex = 2 // project has only 1 yuanbao platform // after opts.PlatformIndex = 1 // 1-based: targets the single platform
Defensive patterns
Strategy: validation
Validate before calling
count := countYuanbaoPlatforms(cfg, opts.ProjectName)
if opts.PlatformIndex > count {
return fmt.Errorf("index %d > %d yuanbao platform(s)", opts.PlatformIndex, count)
} Type guard
func indexInRange(idx, count int) bool { return idx >= 0 && idx <= count } Try / catch
if err != nil {
if strings.Contains(err.Error(), "out of range") {
slog.Error("the error message states the valid platform count; adjust index", "err", err)
return err
}
return err
} Prevention
- Remember indexing: 0 = first/default, N targets the Nth yuanbao platform (1-based)
- Recompute stored indices after adding/removing platforms
- The error message includes the actual count — read it before retrying
When it happens
Trigger: Project has 1 yuanbao platform but the call passes PlatformIndex: 2 or higher; a script iterating platforms with a bad upper bound; after deleting a platform, stored indices become stale and now exceed the remaining count.
Common situations: User-assumed 0-based indexing (passing 1 to mean 'first' works only because 1 maps to position 0, but passing 2 with a single platform fails); automation reading an old index from a saved state file.
Related errors
- config: %s.history_max_len must be >= 0
- project %q has no yuanbao platform
- cloud_web: token is required
- tuitui: history_limit must be non-negative
- cron project not found
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/0cfc52bc64301aa0.
Report an issue: GitHub.