{"id":"7f6bd2cf125d3925","repo":"gofiber/fiber","slug":"unsupported-value-type-t","errorCode":null,"errorMessage":"unsupported value type: %T","messagePattern":"unsupported value type: %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"binder/mapping.go","lineNumber":373,"sourceCode":"\t\treturn content[:i]\n\t}\n\treturn content\n}\n\nfunc formatBindData[T, K any](aliasTag string, out any, data map[string][]T, key string, value K, enableSplitting, supportBracketNotation bool) error { //nolint:revive // it's okay\n\tvar err error\n\tif supportBracketNotation && strings.IndexByte(key, '[') >= 0 {\n\t\tkey, err = parseParamSquareBrackets(key)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\n\tswitch v := any(value).(type) {\n\tcase string:\n\t\tdataMap, ok := any(data).(map[string][]string)\n\t\tif !ok {\n\t\t\treturn fmt.Errorf(\"unsupported value type: %T\", value)\n\t\t}\n\n\t\tassignBindData(aliasTag, out, dataMap, key, v, enableSplitting)\n\tcase []string:\n\t\tdataMap, ok := any(data).(map[string][]string)\n\t\tif !ok {\n\t\t\treturn fmt.Errorf(\"unsupported value type: %T\", value)\n\t\t}\n\n\t\tfor _, val := range v {\n\t\t\tassignBindData(aliasTag, out, dataMap, key, val, enableSplitting)\n\t\t}\n\tcase []*multipart.FileHeader:\n\t\tfor _, val := range v {\n\t\t\tvalT, ok := any(val).(T)\n\t\t\tif !ok {\n\t\t\t\treturn fmt.Errorf(\"unsupported value type: %T\", value)\n\t\t\t}","sourceCodeStart":355,"sourceCodeEnd":391,"githubUrl":"https://github.com/gofiber/fiber/blob/9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c/binder/mapping.go#L355-L391","documentation":"Returned at binder/mapping.go:373 inside the generic formatBindData[T,K] when value is a string but the data map fails the any(data).(map[string][]string) assertion. formatBindData is called by the built-in binders (header/cookie/query/form/resp_header) with their T/K consistently, so this fires only when the generic is instantiated with mismatched types — i.e. a custom binder passes a string value while its data map is keyed for a different element type (e.g. files). It is a defensive invariant violation inside the binder layer.","triggerScenarios":"A custom CustomBinder implementation calls binder.formatBindData with K=string but supplies a data map of type map[string][]*multipart.FileHeader (or any non-string element), so the runtime type assertion fails. The built-in binders never hit this because they instantiate T/K coherently.","commonSituations":"Writing a custom binder for a non-standard source and reusing formatBindData with the wrong map/value type combo; copy-pasting a built-in binder and changing one type argument but not the map.","solutions":["Don't call formatBindData directly from app code — use the provided Bind().Header/Query/Cookie/Body/URI/Custom flow.","If writing a custom binder, instantiate T and K consistently with the data map you pass (string values require map[string][]string).","Unit-test the custom binder with a representative request so type mismatches surface immediately."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"// Prefer the built-in binders; if you must call formatBindData, instantiate\n// T and K consistently with the data map.\nvar data = map[string][]string{}\nif err := formatBindData[string, string](\"query\", out, data, key, \"value\", false, false); err != nil {\n    return err\n}","typeGuard":"// Ensure the data map element type matches the value type before calling.\nfunc assertStringData(data any) (map[string][]string, bool) {\n    m, ok := data.(map[string][]string)\n    return m, ok\n}","tryCatchPattern":null,"preventionTips":["Avoid calling binder.formatBindData from application code; use Bind().Query/Header/Cookie/Body/URI.","In custom binders, keep the generic element type T aligned with both the data map and the value type.","Unit-test custom binders with representative inputs to catch type mismatches early."],"tags":["binding","binder","internal","type-mismatch","reflection"],"analyzedSha":"9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c","analyzedAt":"2026-08-04T21:44:03.395Z","schemaVersion":2}