chenhg5/cc-connect · error
platform index %d out of range: project %q has %d feishu/lar
Error message
platform index %d out of range: project %q has %d feishu/lark platform(s)
What it means
When opts.PlatformIndex > 0 the caller selects the Nth feishu/lark platform within the project (1-based). If that position is not a valid index into the collected candidate list, the helper errors with the requested index and the actual count of feishu/lark platforms, making the mismatch explicit.
Source
Thrown at config/config.go:2077
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 == "feishu" || t == "lark" {
candidates = append(candidates, i)
}
}
if len(candidates) == 0 {
return nil, fmt.Errorf("project %q has no feishu/lark 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 feishu/lark platform(s)",
opts.PlatformIndex, opts.ProjectName, len(candidates),
)
}
absIdx := candidates[targetPos]
platform := &proj.Platforms[absIdx]
if opts.PlatformType != "" {
platform.Type = opts.PlatformType
}
if platform.Options == nil {
platform.Options = map[string]any{}
}
platform.Options["app_id"] = strings.TrimSpace(opts.AppID)
platform.Options["app_secret"] = strings.TrimSpace(opts.AppSecret)
allowFrom := strings.TrimSpace(stringOption(platform.Options["allow_from"]))View on GitHub (pinned to 4000b2338a)
Solutions
- Set opts.PlatformIndex to 0 (or leave it unset) to target the first feishu/lark platform.
- Count the feishu/lark platform blocks in the project's config and use an index within 1..N.
- Add another feishu platform entry if a second one is genuinely needed.
Example fix
// before: project has 1 feishu platform
opts := config.EnsureFeishuOptions{ProjectName: "demo", PlatformIndex: 2}
// after
opts := config.EnsureFeishuOptions{ProjectName: "demo", PlatformIndex: 1} // or 0 Defensive patterns
Strategy: validation
Validate before calling
count := countFeishuPlatforms(proj)
if opts.PlatformIndex > count { return fmt.Errorf("index %d > %d feishu platforms", opts.PlatformIndex, count) } Type guard
func platformIndexInRange(idx, count int) bool { return idx >= 0 && idx <= count } Prevention
- Default to PlatformIndex 0 unless multiple feishu platforms exist
- Count only feishu/lark platforms, not all platforms
- Re-count after any config edit that adds/removes platforms
When it happens
Trigger: Calling the ensure-feishu-platform API (config/config.go:2077) with opts.PlatformIndex greater than the number of feishu/lark platforms in the project, or a negative value that slipped past earlier validation (PlatformIndex < 0 is rejected earlier; this fires when index >= count).
Common situations: Caller assumes a platform exists (e.g. asks for index 2 when only one feishu platform is configured); caller counted all platforms including non-feishu ones; config was edited and a feishu platform was removed, shifting the count.
Related errors
- parse existing Agy hooks %s: %w
- marshal Agy hooks overlay: %w
- tmux: 'session' option is required (name of the tmux session
- tmux: session %q does not exist and auto_create is disabled
- tmux: create session %q: %w
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/fb33887d0959ea6e.
Report an issue: GitHub.