kubernetes/kops · error

cannot interpret %q value as int16

Error message

cannot interpret %q value as int16

What it means

The target field is int16; strconv.ParseInt(s,10,16) failed, meaning the value is not an integer or exceeds the int16 range (-32768..32767).

Source

Thrown at util/pkg/reflectutils/access.go:211

	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)
		case "int32":
			v, err := strconv.ParseInt(newValue, 10, 32)
			if err != nil {
				return fmt.Errorf("cannot interpret %q value as int32", newValue)
			}
			v32 := int32(v)
			newV = reflect.ValueOf(v32)
		case "int64":
			v, err := strconv.ParseInt(newValue, 10, 64)
			if err != nil {
				return fmt.Errorf("cannot interpret %q value as int64", newValue)
			}
			v64 := int64(v)
			newV = reflect.ValueOf(v64)
		default:

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Use a value within int16 range (-32768..32767).
  2. Verify the field type; ports above 32767 belong in int/int32 fields.
  3. Pre-validate with strconv.ParseInt(v,10,16) before calling.

Example fix

// before
SetString(&c, "spec.someInt16Field", "40000") // overflows int16
// after
SetString(&c, "spec.someInt16Field", "32000")
Defensive patterns

Strategy: validation

Validate before calling

if _, err := strconv.ParseInt(val, 10, 16); err != nil {
    return fmt.Errorf("value %q does not fit int16", val)
}

Type guard

func isInt16(s string) bool {
    _, err := strconv.ParseInt(s, 10, 16)
    return err == nil
}

Try / catch

if err := SetString(&obj, path, val); err != nil {
    if strings.Contains(err.Error(), "as int16") {
        return fmt.Errorf("%q must be an integer in [-32768, 32767]", val)
    }
    return err
}

Prevention

When it happens

Trigger: SetString(&obj, "spec.port16", "70000") or any non-numeric string on an int16 field.

Common situations: Port or small-range numeric fields (e.g. node port ranges) given out-of-range values like 65535+ in `kops set cluster` commands.

Related errors


AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05). Data as JSON: /api/errors/326f09f8e5eea745. Report an issue: GitHub.