{"record":{"id":"3ad1ad2818e4bc74","repo":"gofiber/fiber","slug":"binder-map-is-not-convertible-to-map-string-strin","errorCode":null,"errorMessage":"binder: map is not convertible to map[string]string or map[string][]string","messagePattern":"binder: map is not convertible to map\\[string\\]string or map\\[string\\]\\[\\]string","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"binder/binder.go","lineNumber":20,"sourceCode":"\nimport (\n\t\"errors\"\n\t\"sync\"\n)\n\nconst (\n\tbindingURI        = \"uri\"\n\tbindingForm       = \"form\"\n\tbindingQuery      = \"query\"\n\tbindingHeader     = \"header\"\n\tbindingRespHeader = \"respHeader\"\n\tbindingCookie     = \"cookie\"\n)\n\n// Binder errors\nvar (\n\tErrSuitableContentNotFound = errors.New(\"binder: suitable content not found to parse body\")\n\tErrMapNotConvertible       = errors.New(\"binder: map is not convertible to map[string]string or map[string][]string\")\n\tErrMapNilDestination       = errors.New(\"binder: map destination is nil and cannot be initialized\")\n\tErrInvalidDestinationValue = errors.New(\"binder: invalid destination value\")\n\tErrUnmatchedBrackets       = errors.New(\"unmatched brackets\")\n)\n\nvar errPoolTypeAssertion = errors.New(\"failed to type-assert to T\")\n\nvar HeaderBinderPool = sync.Pool{\n\tNew: func() any {\n\t\treturn &HeaderBinding{}\n\t},\n}\n\nvar RespHeaderBinderPool = sync.Pool{\n\tNew: func() any {\n\t\treturn &RespHeaderBinding{}\n\t},\n}","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/gofiber/fiber/blob/a105acad6c1e4576a77f01e02973f67e962bb58d/binder/binder.go#L2-L38","documentation":"Returned by parseToMap (binder/mapping.go:153 and :160) when the destination map's element kind is Slice or String but the concrete type is not exactly map[string][]string or map[string]string. The binder can only populate those two shapes from form/query data; other slice/string element types (e.g. map[string][]int, map[string]MyString) cannot be filled without per-element conversion and are rejected.","triggerScenarios":"Calling Bind.Query/Bind.Form (or any path that lands in parseToMap) with a destination of type map[string][]int, map[string]customStringType, or any map whose value kind is Slice/String but whose full type is not one of the two supported exact types.","commonSituations":"Trying to bind query parameters into a strongly-typed map like map[string][]int expecting automatic integer parsing; using a named string type as the map value; migrating a handler from map[string]string to a generic map[string]any (the latter is treated as a no-op, not an error).","solutions":["Change the destination to map[string][]string or map[string]string — the only two map shapes parseToMap populates.","For typed values, bind into a struct with properly tagged fields instead of a map; the struct decoder handles type conversion.","If you need map[string][]int, bind to map[string][]string first and convert values in a second pass with strconv.Atoi.","Use map[string]any if you want the binder to skip the map (no-op) rather than error."],"exampleFix":"// before\nm := make(map[string][]int)\nerr := c.Bind().Query(&m) // ErrMapNotConvertible\n\n// after\nvar s struct {\n    IDs []int `query:\"ids\"`\n}\nerr := c.Bind().Query(&s)","handlingStrategy":"type-guard","validationCode":"// Confirm the destination is one of the two supported map shapes\nfunc isSupportedMap(t reflect.Type) bool {\n    return t == reflect.TypeFor[map[string]string]() ||\n        t == reflect.TypeFor[map[string][]string]()\n}","typeGuard":"func isSupportedMapDest(v any) bool {\n    t := reflect.TypeOf(v)\n    if t == nil || t.Kind() != reflect.Ptr { return false }\n    t = t.Elem()\n    return t == reflect.TypeFor[map[string]string]() || t == reflect.TypeFor[map[string][]string]()\n}","tryCatchPattern":"if err := c.Bind().Query(&m); err != nil {\n    if errors.Is(err, binder.ErrMapNotConvertible) {\n        // switch to a struct destination or map[string][]string\n    }\n    return err\n}","preventionTips":["Prefer structs over maps for typed query/form binding.","Restrict map destinations to map[string]string or map[string][]string.","Add a unit test per handler that exercises the bind with realistic input."],"tags":["binding","reflection","map","fiber"],"backgroundTag":null,"analyzedSha":"a105acad6c1e4576a77f01e02973f67e962bb58d","analyzedAt":"2026-08-11T17:33:26.942Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}