{"record":{"id":"2a94cd7a3c1f4312","repo":"kubernetes/kops","slug":"cannot-interpret-q-value-as-integer","errorCode":null,"errorMessage":"cannot interpret %q value as integer","messagePattern":"cannot interpret %q value as integer","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"util/pkg/reflectutils/access.go","lineNumber":205,"sourceCode":"\tvar newV reflect.Value\n\n\tswitch t {\n\tcase \"string\":\n\t\tnewV = reflect.ValueOf(newValue)\n\n\tcase \"bool\":\n\t\tb, err := strconv.ParseBool(newValue)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"cannot interpret %q value as bool\", newValue)\n\t\t}\n\t\tnewV = reflect.ValueOf(b)\n\n\tcase \"int64\", \"int32\", \"int16\", \"int\":\n\t\tswitch t {\n\t\tcase \"int\":\n\t\t\tv, err := strconv.Atoi(newValue)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"cannot interpret %q value as integer\", newValue)\n\t\t\t}\n\t\t\tnewV = reflect.ValueOf(v)\n\t\tcase \"int16\":\n\t\t\tv, err := strconv.ParseInt(newValue, 10, 16)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"cannot interpret %q value as int16\", newValue)\n\t\t\t}\n\t\t\tv16 := int16(v)\n\t\t\tnewV = reflect.ValueOf(v16)\n\t\tcase \"int32\":\n\t\t\tv, err := strconv.ParseInt(newValue, 10, 32)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"cannot interpret %q value as int32\", newValue)\n\t\t\t}\n\t\t\tv32 := int32(v)\n\t\t\tnewV = reflect.ValueOf(v32)\n\t\tcase \"int64\":\n\t\t\tv, err := strconv.ParseInt(newValue, 10, 64)","sourceCodeStart":187,"sourceCodeEnd":223,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/util/pkg/reflectutils/access.go#L187-L223","documentation":"The target field is of type int; strconv.Atoi failed on the supplied string, so it is not a valid base-10 integer (may be empty, contain units, or overflow on 32-bit platforms).","triggerScenarios":"SetString(&obj, \"spec.someInt\", \"12abc\"), \"\", \"1_000\", or a value exceeding int range.","commonSituations":"Passing numbers with thousands separators or units (\"1024MB\") to integer fields via `kops set`; whitespace from shell quoting.","solutions":["Supply a plain base-10 integer string, e.g. \"42\".","Trim whitespace/suffixes (units) from the value before calling.","Pre-validate with strconv.Atoi and surface a clear CLI error.","If the field should accept sizes, change its type to resource.Quantity."],"exampleFix":"// before\nSetString(&c, \"spec.maxInstances\", \"1,000\")\n// after\nSetString(&c, \"spec.maxInstances\", \"1000\")","handlingStrategy":"validation","validationCode":"if _, err := strconv.Atoi(val); err != nil {\n    return fmt.Errorf(\"value %q is not a valid int\", val)\n}","typeGuard":"func isGoInt(s string) bool {\n    _, err := strconv.Atoi(s)\n    return err == nil\n}","tryCatchPattern":"if err := SetString(&obj, path, val); err != nil {\n    if strings.Contains(err.Error(), \"as integer\") {\n        return fmt.Errorf(\"%q is not a plain base-10 integer\", val)\n    }\n    return err\n}","preventionTips":["Strip units/separators before setting integer fields.","Trim shell whitespace and quotes.","Use resource.Quantity fields for sizes instead of raw ints."],"tags":["go","parsing","integer"],"backgroundTag":"invalid-integer-value","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}