{"record":{"id":"fb33887d0959ea6e","repo":"chenhg5/cc-connect","slug":"platform-index-d-out-of-range-project-q-has-d","errorCode":null,"errorMessage":"platform index %d out of range: project %q has %d feishu/lark platform(s)","messagePattern":"platform index (.+?) out of range: project %q has (.+?) feishu/lark platform\\(s\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"config/config.go","lineNumber":2077,"sourceCode":"\n\tproj := &cfg.Projects[projectIdx]\n\tcandidates := make([]int, 0, len(proj.Platforms))\n\tfor i := range proj.Platforms {\n\t\tt := strings.ToLower(strings.TrimSpace(proj.Platforms[i].Type))\n\t\tif t == \"feishu\" || t == \"lark\" {\n\t\t\tcandidates = append(candidates, i)\n\t\t}\n\t}\n\tif len(candidates) == 0 {\n\t\treturn nil, fmt.Errorf(\"project %q has no feishu/lark platform\", opts.ProjectName)\n\t}\n\n\ttargetPos := 0\n\tif opts.PlatformIndex > 0 {\n\t\ttargetPos = opts.PlatformIndex - 1\n\t}\n\tif targetPos < 0 || targetPos >= len(candidates) {\n\t\treturn nil, fmt.Errorf(\n\t\t\t\"platform index %d out of range: project %q has %d feishu/lark platform(s)\",\n\t\t\topts.PlatformIndex, opts.ProjectName, len(candidates),\n\t\t)\n\t}\n\n\tabsIdx := candidates[targetPos]\n\tplatform := &proj.Platforms[absIdx]\n\tif opts.PlatformType != \"\" {\n\t\tplatform.Type = opts.PlatformType\n\t}\n\tif platform.Options == nil {\n\t\tplatform.Options = map[string]any{}\n\t}\n\n\tplatform.Options[\"app_id\"] = strings.TrimSpace(opts.AppID)\n\tplatform.Options[\"app_secret\"] = strings.TrimSpace(opts.AppSecret)\n\n\tallowFrom := strings.TrimSpace(stringOption(platform.Options[\"allow_from\"]))","sourceCodeStart":2059,"sourceCodeEnd":2095,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/config/config.go#L2059-L2095","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before: project has 1 feishu platform\nopts := config.EnsureFeishuOptions{ProjectName: \"demo\", PlatformIndex: 2}\n// after\nopts := config.EnsureFeishuOptions{ProjectName: \"demo\", PlatformIndex: 1} // or 0","handlingStrategy":"validation","validationCode":"count := countFeishuPlatforms(proj)\nif opts.PlatformIndex > count { return fmt.Errorf(\"index %d > %d feishu platforms\", opts.PlatformIndex, count) }","typeGuard":"func platformIndexInRange(idx, count int) bool { return idx >= 0 && idx <= count }","tryCatchPattern":null,"preventionTips":["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"],"tags":["go","config","bounds"],"backgroundTag":"index-out-of-range","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}