{"record":{"id":"2ff72936da63e051","repo":"vitessio/vitess","slug":"getfuncfortype-does-not-support-interface-types-s","errorCode":null,"errorMessage":"GetFuncForType does not support interface types (specify a specific implementation type instead)","messagePattern":"GetFuncForType does not support interface types \\(specify a specific implementation type instead\\)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/viperutil/get_func.go","lineNumber":121,"sourceCode":"\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 {\n\t\t\t\t\t\treturn v.GetStringMapStringSlice\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tcase reflect.Interface:\n\t\t\t\tf = func(v *viper.Viper) func(key string) map[string]any {\n\t\t\t\t\treturn v.GetStringMap","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/viperutil/get_func.go#L103-L139","documentation":"GetFuncForType[T] cannot infer which concrete implementation to construct for an interface-typed value: viper would return raw data with no way to choose the implementing type. It panics with a hint to specify a specific implementation type instead.","triggerScenarios":"Calling viperutil.Configure/GetFuncForType with an interface type parameter (e.g. io.Reader, net.Addr, or a project interface) instead of a concrete type.","commonSituations":"A developer models a pluggable config option by its interface type and expects the config layer to pick the implementation from config values.","solutions":["Use a concrete type as the generic parameter (e.g. *bytes.Buffer rather than io.Reader) and store it in an interface-typed variable afterward","Store a discriminator string in config (e.g. implementation name) and map it to a constructor in code","Pass a custom GetFunc via viperutil.Configure that unmarshals and constructs the right implementation"],"exampleFix":"// before\nr, _ := viperutil.ConfigureAndGet[ io.Reader ](v, \"input\")\n// after\ns, _ := viperutil.ConfigureAndGet[ string ](v, \"input-file\")\nr, err := os.Open(s)","handlingStrategy":"validation","validationCode":"t := reflect.TypeOf(optionValue)\nif t != nil && t.Kind() == reflect.Interface {\n    return errors.New(\"specify a concrete implementation type for viperutil options\")\n}","typeGuard":"func isInterfaceType[T any]() bool {\n    var zero T\n    tt := reflect.TypeOf(zero)\n    return tt != nil && tt.Kind() == reflect.Interface\n}","tryCatchPattern":null,"preventionTips":["Always use concrete types as viperutil generic parameters","Convert to the interface at the call site after retrieval","For pluggable behavior, store a name in config and resolve a constructor map in code"],"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-08T10:18:20.063Z"}