{"record":{"id":"ce2583090bf21c9e","repo":"kubernetes/kops","slug":"cannot-parse-token-q-as-array-index","errorCode":null,"errorMessage":"cannot parse token %q as array-index","messagePattern":"cannot parse token %q as array-index","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"util/pkg/reflectutils/field_path.go","lineNumber":114,"sourceCode":"\t\t\t})\n\n\t\tcase '.', '/':\n\t\t\t// Skip\n\n\t\tcase '[':\n\t\t\t{\n\t\t\t\ttok := scan.Scan()\n\t\t\t\tswitch tok {\n\t\t\t\tcase '*':\n\t\t\t\t\telements = append(elements, FieldPathElement{\n\t\t\t\t\t\tType: FieldPathElementTypeWildcardIndex,\n\t\t\t\t\t})\n\n\t\t\t\tcase scanner.Int:\n\t\t\t\t\tv := scan.TokenText()\n\t\t\t\t\tn, err := strconv.Atoi(v)\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn nil, fmt.Errorf(\"cannot parse token %q as array-index\", v)\n\t\t\t\t\t}\n\t\t\t\t\telements = append(elements, FieldPathElement{\n\t\t\t\t\t\tType:   FieldPathElementTypeArrayIndex,\n\t\t\t\t\t\tnumber: n,\n\t\t\t\t\t})\n\n\t\t\t\tdefault:\n\t\t\t\t\treturn nil, fmt.Errorf(\"unexpected token %v (%s)\", tok, scan.TokenText())\n\t\t\t\t}\n\n\t\t\t\ttok = scan.Scan()\n\t\t\t\tswitch tok {\n\t\t\t\tcase ']':\n\t\t\t\t\t// ok\n\t\t\t\tdefault:\n\t\t\t\t\treturn nil, fmt.Errorf(\"unexpected token %v (%s)\", tok, scan.TokenText())\n\t\t\t\t}\n","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/util/pkg/reflectutils/field_path.go#L96-L132","documentation":"ParseFieldPath lexes field paths; when a bracketed token is scanned as an integer but strconv.Atoi still fails (e.g. an integer literal too large for int), it returns this error. Practically it fires when the text inside brackets cannot be converted to an array index.","triggerScenarios":"Paths like `spec.subnets[99999999999999999999]` — bracket contents scanned as Int but overflowing int — or other oversized/malformed index tokens.","commonSituations":"Copy-paste errors producing absurd index numbers, or generating paths programmatically from string data that was never validated as an index.","solutions":["Use a small, in-range numeric index like [0], [1]","List actual elements (`kops get instancegroups`) and index existing entries","Fix path-generation code to validate indices before building the path"],"exampleFix":"// before\nUnset(c, \"spec.etcdClusters[99999999999999999999].name\")\n// after\nUnset(c, \"spec.etcdClusters[0].name\")","handlingStrategy":"validation","validationCode":"idx := \"0\"\nn, err := strconv.Atoi(idx)\nif err != nil || n < 0 {\n\treturn fmt.Errorf(\"%q is not a valid array index\", idx)\n}","typeGuard":"func isValidArrayIndex(s string) bool {\n\tn, err := strconv.Atoi(s)\n\treturn err == nil && n >= 0 && n < 1<<31\n}","tryCatchPattern":"if err := doUnset(); err != nil && strings.Contains(err.Error(), \"as array-index\") {\n\t// correct the bracketed index and retry\n}","preventionTips":["Only use small non-negative integer indices in brackets","Enumerate real elements first (e.g. kops get instancegroups) and index existing entries","Validate programmatically generated paths before use"],"tags":["field-path","parsing","array-index"],"backgroundTag":"invalid-field-path","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}