{"record":{"id":"7faae622cfb2400a","repo":"vitessio/vitess","slug":"getfuncfortype-does-not-support-array-types","errorCode":null,"errorMessage":"GetFuncForType does not support array types","messagePattern":"GetFuncForType does not support array types","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/viperutil/get_func.go","lineNumber":115,"sourceCode":"\t\tf = func(v *viper.Viper) func(key string) float32 {\n\t\t\treturn func(key string) float32 {\n\t\t\t\treturn float32(v.GetFloat64(key))\n\t\t\t}\n\t\t}\n\tcase reflect.Float64:\n\t\tf = func(v *viper.Viper) func(key string) float64 {\n\t\t\treturn v.GetFloat64\n\t\t}\n\tcase reflect.Complex64:\n\t\tf = getComplex[complex64](64)\n\tcase reflect.Complex128:\n\t\tf = getComplex[complex128](128)\n\tcase reflect.Array:\n\t\t// Even though the code would be extremely similar to slice types, we\n\t\t// cannot support arrays because there's no way to write a function that\n\t\t// returns, say, [N]int, for some value of N which we only know at\n\t\t// runtime.\n\t\tpanic(\"GetFuncForType does not support array types\")\n\tcase reflect.Chan:\n\t\tpanic(\"GetFuncForType does not support channel types\")\n\tcase reflect.Func:\n\t\tpanic(\"GetFuncForType does not support function types\")\n\tcase reflect.Interface:\n\t\tpanic(\"GetFuncForType does not support interface types (specify a specific implementation type instead)\")\n\tcase reflect.Map:\n\t\tswitch typ.Key().Kind() {\n\t\tcase reflect.String:\n\t\t\tswitch val := typ.Elem(); val.Kind() {\n\t\t\tcase reflect.String:\n\t\t\t\tf = func(v *viper.Viper) func(key string) map[string]string {\n\t\t\t\t\treturn v.GetStringMapString\n\t\t\t\t}\n\t\t\tcase reflect.Slice:\n\t\t\t\tswitch val.Elem().Kind() {\n\t\t\t\tcase reflect.String:\n\t\t\t\t\tf = func(v *viper.Viper) func(key string) map[string][]string {","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/viperutil/get_func.go#L97-L133","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Change the option's type to a slice ([]int, []byte) and convert to an array after retrieval","Use a struct or named type holding the values as individual fields","If array support is truly needed, add a reflect.Array case mirroring the slice case in get_func.go"],"exampleFix":"// before\nviperutil.Configure(key, viperutil.Options[ [4]byte ]{ GetFunc: nil })\n// after\nb, _ := viperutil.ConfigureAndGet[ []byte ](v, key)\nvar arr [4]byte\ncopy(arr[:], b)","handlingStrategy":"validation","validationCode":"// Guard before calling Configure/GetFuncForType\nif reflect.TypeOf(optionValue).Kind() == reflect.Array {\n    return errors.New(\"use a slice instead of a fixed-size array for viperutil options\")\n}","typeGuard":"func isArrayType[T any]() bool {\n    var zero T\n    return reflect.ValueOf(zero).Kind() == reflect.Array\n}","tryCatchPattern":"func() {\n    defer func() {\n        if r := recover(); r != nil {\n            log.Fatalf(\"unsupported viperutil type: %v\", r)\n        }\n    }()\n    viperutil.Configure[T](key, opts)\n}()","preventionTips":["Model fixed-size config data as slices ([]byte, []int) and convert after retrieval","Supported kinds: bool, ints, floats, complex, string, slice, string-keyed map, struct via UnmarshalKey — anything else needs a custom GetFunc","Search get_func.go's kind switch before registering a new option type"],"tags":["go","viper","config","generics","panic"],"backgroundTag":"unsupported-config-type","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}