go-playground/validator · error

Bad field type %s

Error message

Bad field type %s

What it means

Panics inside the isOneOf (oneof) validator when the field's kind is not supported. oneof compares the field value against the parameter list as a decimal string, which only works for string kinds and signed/unsigned integers; any other kind (floats, bools, slices, structs) cannot be stringified this way, so the guard panics naming the offending field type. It also propagates to the inverse isNoneOf tag, which calls isOneOf.

Source

Thrown at baked_in.go:342

func isHTML(fl FieldLevel) bool {
	return hTMLRegex().MatchString(fl.Field().String())
}

func isOneOf(fl FieldLevel) bool {
	vals := parseOneOfParam2(fl.Param())

	field := fl.Field()

	var v string
	switch field.Kind() {
	case reflect.String:
		v = field.String()
	case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
		v = strconv.FormatInt(field.Int(), 10)
	case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
		v = strconv.FormatUint(field.Uint(), 10)
	default:
		panic(fmt.Sprintf("Bad field type %s", field.Type()))
	}

	return slices.Contains(vals, v)
}

// isOneOfCI is the validation function for validating if the current field's value is one of the provided string values (case insensitive).
func isOneOfCI(fl FieldLevel) bool {
	vals := parseOneOfParam2(fl.Param())
	field := fl.Field()

	if field.Kind() != reflect.String {
		panic(fmt.Sprintf("Bad field type %s", field.Type()))
	}

	return slices.ContainsFunc(vals, func(val string) bool {
		return strings.EqualFold(val, field.String())
	})
}

View on GitHub (pinned to facf128d2e)

Solutions

  1. Only use oneof on string or integer-typed fields
  2. For numeric types not supported, compare via a custom registered validator
  3. For float fields, use a custom validator or convert the field to a supported type
  4. Add unit tests asserting the field kind before tagging with oneof
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at baked_in.go:342 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of go-playground/validator@facf128d2e (2026-09-02). Data as JSON: /api/errors/700d419c6c77a913. Report an issue: GitHub.