kubernetes/kops · error
cannot interpret value as bool
Error message
cannot interpret %q value as bool
What it means
The target field is a bool; setType uses strconv.ParseBool on the string value and this error is returned when the string is not one of 1,t,T,TRUE,true,True,0,f,F,FALSE,false,False. The offending string is quoted in the message.
Solutions
- Use a ParseBool-accepted literal: true/false, 1/0, t/f, TRUE/FALSE, True/False.
- Change "yes"/"no"/"on"/"off" to true/false before calling.
- Pre-validate with strconv.ParseBool and report a friendly message to the user.
Example fix
// before SetString(&ig, "spec.machineType", ...) // e.g. "yes" on a bool field SetString(&ig, "spec.spot", "yes") // after SetString(&ig, "spec.spot", "true")
Defensive patterns
Strategy: validation
Validate before calling
if _, err := strconv.ParseBool(val); err != nil {
return fmt.Errorf("value %q is not a valid Go bool (use true/false/1/0)", val)
} Type guard
func isGoBool(s string) bool {
_, err := strconv.ParseBool(s)
return err == nil
} Try / catch
if err := SetString(&obj, path, val); err != nil {
if strings.Contains(err.Error(), "as bool") {
return fmt.Errorf("%q is not a bool; use true or false", val)
}
return err
} Prevention
- Normalize yes/no/on/off to true/false in CLI wrappers.
- Remember Go accepts only 1/0/t/f/true/false and mixed-case variants.
- Trim whitespace from user input before setting.
When it happens
Trigger: SetString(&obj, "spec.someBool", "yes") or "enabled" or "1.0" — any value ParseBool rejects.
Common situations: Shell one-liners using `kops set cluster spec.X.enabled=yes`; YAML-style true/false variants like "on"/"off" that Go doesn't accept.
Related errors
- cannot interpret value as int16
- cannot interpret value as int32
- cannot interpret value as int64
- cannot interpret value as integer
- unable to parse sha
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/7529775224719223.
Report an issue: GitHub.
Appendix: source
Thrown at util/pkg/reflectutils/access.go:196
v.SetMapIndex(reflect.ValueOf(name), valueArray)
default:
return fmt.Errorf("unhandled type %q", t)
}
return nil
}
var newV reflect.Value
switch t {
case "string":
newV = reflect.ValueOf(newValue)
case "bool":
b, err := strconv.ParseBool(newValue)
if err != nil {
return fmt.Errorf("cannot interpret %q value as bool", newValue)
}
newV = reflect.ValueOf(b)
case "int64", "int32", "int16", "int":
switch t {
case "int":
v, err := strconv.Atoi(newValue)
if err != nil {
return fmt.Errorf("cannot interpret %q value as integer", newValue)
}
newV = reflect.ValueOf(v)
case "int16":
v, err := strconv.ParseInt(newValue, 10, 16)
if err != nil {
return fmt.Errorf("cannot interpret %q value as int16", newValue)
}
v16 := int16(v)
newV = reflect.ValueOf(v16)View on GitHub (pinned to 4c8573c808)