{"record":{"id":"2c2acf81df789787","repo":"chenhg5/cc-connect","slug":"platform-index-must-be-0","errorCode":null,"errorMessage":"platform index must be >= 0","messagePattern":"platform index must be >= 0","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"config/config.go","lineNumber":2033,"sourceCode":"}\n\n// SaveFeishuPlatformCredentials updates app_id/app_secret for a project's\n// Feishu/Lark platform and persists the config atomically.\nfunc SaveFeishuPlatformCredentials(opts FeishuCredentialUpdateOptions) (*FeishuCredentialUpdateResult, error) {\n\tconfigMu.Lock()\n\tdefer configMu.Unlock()\n\n\tif ConfigPath == \"\" {\n\t\treturn nil, fmt.Errorf(\"config path not set\")\n\t}\n\tif strings.TrimSpace(opts.ProjectName) == \"\" {\n\t\treturn nil, fmt.Errorf(\"project name is required\")\n\t}\n\tif strings.TrimSpace(opts.AppID) == \"\" || strings.TrimSpace(opts.AppSecret) == \"\" {\n\t\treturn nil, fmt.Errorf(\"app_id and app_secret are required\")\n\t}\n\tif opts.PlatformIndex < 0 {\n\t\treturn nil, fmt.Errorf(\"platform index must be >= 0\")\n\t}\n\tif opts.PlatformType != \"\" && opts.PlatformType != \"feishu\" && opts.PlatformType != \"lark\" {\n\t\treturn nil, fmt.Errorf(\"invalid platform type %q (want feishu or lark)\", opts.PlatformType)\n\t}\n\n\tdata, err := os.ReadFile(ConfigPath)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"read config: %w\", err)\n\t}\n\traw := string(data)\n\tcfg := &Config{}\n\tif err := toml.Unmarshal(data, cfg); err != nil {\n\t\treturn nil, fmt.Errorf(\"parse config: %w\", err)\n\t}\n\n\tprojectIdx := -1\n\tfor i := range cfg.Projects {\n\t\tif cfg.Projects[i].Name == opts.ProjectName {","sourceCodeStart":2015,"sourceCodeEnd":2051,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/config/config.go#L2015-L2051","documentation":"When updating credentials the caller may target a specific platform entry inside the project via opts.PlatformIndex. A negative index is invalid because it cannot address any slice element, so the function rejects it before reading the config. Zero and positive values are accepted (and later bounds-checked against the actual platform list).","triggerScenarios":"Calling config.SaveFeishuPlatformCredentials with opts.PlatformIndex set to -1 or any negative number, typically from uninitialized zero-value confusion or a 'not specified' sentinel value.","commonSituations":"Using -1 as a 'first platform' or 'unset' sentinel; forgetting to initialize the field in a dynamically built options struct; off-by-one arithmetic when computing the index upstream.","solutions":["Set opts.PlatformIndex to a valid zero-based index (use 0 for the first platform).","Leave the struct field at 0 instead of -1 when targeting the first Feishu platform.","Clamp/validate the index at the caller: if idx < 0 { idx = 0 } before calling."],"exampleFix":"// before\nopts := config.FeishuCredentialUpdateOptions{ProjectName: \"p\", AppID: \"cli_a\", AppSecret: \"s\", PlatformIndex: -1}\n\n// after\nopts := config.FeishuCredentialUpdateOptions{ProjectName: \"p\", AppID: \"cli_a\", AppSecret: \"s\", PlatformIndex: 0}","handlingStrategy":"validation","validationCode":"if opts.PlatformIndex < 0 {\n    opts.PlatformIndex = 0\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use 0 (not -1) as the default/first platform index in your caller code.","Validate zero-based indices wherever they are computed (flags, parsers, loops).","Document the index convention (0-based) at the option definition site."],"tags":["config","go","validation","index"],"backgroundTag":"argument-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"}