vitessio/vitess · error

GetFuncForType does not support array types

Error message

GetFuncForType does not support array types

What it means

go/viperutil's generic GetFuncForType[T] builds a typed getter for a config value based on its reflect.Kind. Arrays are explicitly unsupported: there is no way to write a function returning [N]int when N is only known at runtime. The function panics rather than returning a wrong or lossy result.

Source

Thrown at go/viperutil/get_func.go:115

		f = func(v *viper.Viper) func(key string) float32 {
			return func(key string) float32 {
				return float32(v.GetFloat64(key))
			}
		}
	case reflect.Float64:
		f = func(v *viper.Viper) func(key string) float64 {
			return v.GetFloat64
		}
	case reflect.Complex64:
		f = getComplex[complex64](64)
	case reflect.Complex128:
		f = getComplex[complex128](128)
	case reflect.Array:
		// Even though the code would be extremely similar to slice types, we
		// cannot support arrays because there's no way to write a function that
		// returns, say, [N]int, for some value of N which we only know at
		// runtime.
		panic("GetFuncForType does not support array types")
	case reflect.Chan:
		panic("GetFuncForType does not support channel types")
	case reflect.Func:
		panic("GetFuncForType does not support function types")
	case reflect.Interface:
		panic("GetFuncForType does not support interface types (specify a specific implementation type instead)")
	case reflect.Map:
		switch typ.Key().Kind() {
		case reflect.String:
			switch val := typ.Elem(); val.Kind() {
			case reflect.String:
				f = func(v *viper.Viper) func(key string) map[string]string {
					return v.GetStringMapString
				}
			case reflect.Slice:
				switch val.Elem().Kind() {
				case reflect.String:
					f = func(v *viper.Viper) func(key string) map[string][]string {

View on GitHub (pinned to 01a25a7d17)

Solutions

  1. Change the option's type to a slice ([]int, []byte) and convert to an array after retrieval
  2. Use a struct or named type holding the values as individual fields
  3. If array support is truly needed, add a reflect.Array case mirroring the slice case in get_func.go

Example fix

// before
viperutil.Configure(key, viperutil.Options[ [4]byte ]{ GetFunc: nil })
// after
b, _ := viperutil.ConfigureAndGet[ []byte ](v, key)
var arr [4]byte
copy(arr[:], b)
Defensive patterns

Strategy: validation

Validate before calling

// Guard before calling Configure/GetFuncForType
if reflect.TypeOf(optionValue).Kind() == reflect.Array {
    return errors.New("use a slice instead of a fixed-size array for viperutil options")
}

Type guard

func isArrayType[T any]() bool {
    var zero T
    return reflect.ValueOf(zero).Kind() == reflect.Array
}

Try / catch

func() {
    defer func() {
        if r := recover(); r != nil {
            log.Fatalf("unsupported viperutil type: %v", r)
        }
    }()
    viperutil.Configure[T](key, opts)
}()

Prevention

When it happens

Trigger: Calling viperutil.Configure/GetFuncForType with a generic type parameter or registered option whose type is a fixed-size array (e.g. [4]int, [16]byte).

Common situations: A developer registers a config option for a fixed-size array (common for keys, hashes, byte buffers) assuming slices and arrays behave the same in viper.

Related errors


AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01). Data as JSON: /api/errors/7faae622cfb2400a. Report an issue: GitHub.