{"record":{"id":"410a268bfbd4c23c","repo":"chenhg5/cc-connect","slug":"platform-index-d-out-of-range-project-q-has-d-410a26","errorCode":null,"errorMessage":"platform index %d out of range: project %q has %d weixin platform(s)","messagePattern":"platform index (.+?) out of range: project %q has (.+?) weixin platform\\(s\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"config/config.go","lineNumber":2441,"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 == \"weixin\" {\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 weixin 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 weixin 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\ttoken := strings.TrimSpace(opts.Token)\n\tplatform.Options[\"token\"] = token\n\n\tif u := strings.TrimSpace(opts.BaseURL); u != \"\" {\n\t\tplatform.Options[\"base_url\"] = u\n\t}\n\tif u := strings.TrimSpace(opts.CDNBaseURL); u != \"\" {","sourceCodeStart":2423,"sourceCodeEnd":2459,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/config/config.go#L2423-L2459","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Set opts.PlatformIndex to a value between 1 and the number of weixin platforms in the project","Omit PlatformIndex (or pass 0) to target the first weixin platform","Count the [[projects.platforms]] blocks with type = \"weixin\" under the project to get the valid range"],"exampleFix":"// before\nopts.PlatformIndex = 3 // project only has 1 weixin platform\n// after\nopts.PlatformIndex = 1","handlingStrategy":"validation","validationCode":"var weixinCount int\nfor _, pl := range proj.Platforms {\n    if strings.ToLower(strings.TrimSpace(pl.Type)) == \"weixin\" { weixinCount++ }\n}\nif opts.PlatformIndex < 0 || opts.PlatformIndex > weixinCount {\n    return fmt.Errorf(\"PlatformIndex must be 1..%d\", weixinCount)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remember PlatformIndex counts only weixin platforms, not all platforms","Default to omitting PlatformIndex when the project has a single weixin platform","Recount indices after removing platforms from config.toml"],"tags":["config","index-out-of-range","weixin"],"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"}