{"record":{"id":"0cfc52bc64301aa0","repo":"chenhg5/cc-connect","slug":"platform-index-d-out-of-range-project-q-has-d-0cfc52","errorCode":null,"errorMessage":"platform index %d out of range: project %q has %d yuanbao platform(s)","messagePattern":"platform index (.+?) out of range: project %q has (.+?) yuanbao platform\\(s\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"config/config.go","lineNumber":2751,"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 == \"yuanbao\" {\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 yuanbao 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 yuanbao 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 platform.Options == nil {\n\t\tplatform.Options = map[string]any{}\n\t}\n\n\tplatform.Options[\"bot_token\"] = botToken\n\n\tallowFrom := strings.TrimSpace(stringOption(platform.Options[\"allow_from\"]))\n\tif v := strings.TrimSpace(opts.AllowFrom); v != \"\" {\n\t\tallowFrom = v\n\t\tplatform.Options[\"allow_from\"] = v\n\t}","sourceCodeStart":2733,"sourceCodeEnd":2769,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/config/config.go#L2733-L2769","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nopts.PlatformIndex = 2 // project has only 1 yuanbao platform\n// after\nopts.PlatformIndex = 1 // 1-based: targets the single platform","handlingStrategy":"validation","validationCode":"count := countYuanbaoPlatforms(cfg, opts.ProjectName)\nif opts.PlatformIndex > count {\n    return fmt.Errorf(\"index %d > %d yuanbao platform(s)\", opts.PlatformIndex, count)\n}","typeGuard":"func indexInRange(idx, count int) bool { return idx >= 0 && idx <= count }","tryCatchPattern":"if err != nil {\n    if strings.Contains(err.Error(), \"out of range\") {\n        slog.Error(\"the error message states the valid platform count; adjust index\", \"err\", err)\n        return err\n    }\n    return err\n}","preventionTips":["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"],"tags":["config","range","platform"],"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"}