gofr-dev/gofr · error
unsupported kind
Error message
unsupported kind
What it means
errUnsupportedKind is returned by setSliceOrArrayValue when the element kind of a slice/array field in the bind target is not one of the kinds the multipart binder supports (e.g. trying to bind strings into a slice of maps, channels, or other complex kinds). Only basic kinds can be constructed from multipart string values.
Source
Thrown at pkg/gofr/http/multipart_file_bind.go:16
package http
import (
"errors"
"io"
"mime/multipart"
"reflect"
"strconv"
"gofr.dev/pkg/gofr/file"
)
var (
errUnsupportedInterfaceType = errors.New("unsupported interface value type")
errDataLengthExceeded = errors.New("data length exceeds array capacity")
errUnsupportedKind = errors.New("unsupported kind")
errSettingValueFailure = errors.New("error setting value at index")
errNotAStruct = errors.New("provided value is not a struct")
errUnexportedField = errors.New("cannot set field; it might be unexported")
errUnsupportedFieldType = errors.New("unsupported type for field")
errFieldsNotSet = errors.New("no fields were set")
)
type formData struct {
fields map[string][]string
files map[string][]*multipart.FileHeader
}
func (uf *formData) mapStruct(val reflect.Value, field *reflect.StructField) (bool, error) {
vKind := val.Kind()
if field == nil {
// Check if val is not a struct
if vKind != reflect.Struct {View on GitHub (pinned to 187eb24962)
Solutions
- Use slices of primitive types ([]string, []int, etc.) in multipart bind targets
- Pre-process multipart values manually for complex element types instead of relying on automatic binding
- Add a validation step that checks field kinds before binding and rejects unsupported shapes with a clear client message
Example fix
// before
type Upload struct { Items []map[string]string }
// after
type Upload struct { ItemIDs []string } Defensive patterns
Strategy: type-guard
Validate before calling
// reject unsupported element kinds before binding
if k := t.Field(i).Type.Elem().Kind(); k == reflect.Map || k == reflect.Chan || k == reflect.Struct { return errUnsupportedKind } Type guard
func supportedSliceKind(t reflect.Type) bool {
if t.Kind() != reflect.Slice && t.Kind() != reflect.Array { return false }
switch t.Elem().Kind() {
case reflect.String, reflect.Int, reflect.Int64, reflect.Float64, reflect.Bool:
return true
}
return false
} Try / catch
if err := bind.Struct(&upload); err != nil { http.Error(w, err.Error(), http.StatusBadRequest); return } Prevention
- Bind only slices of primitives from multipart data
- Handle nested/complex payloads via JSON request bodies instead
- Validate struct field kinds in unit tests for bind targets
When it happens
Trigger: Binding multipart data into a struct field like []map[string]string, []chan int, or [][]byte-style composite element kinds unsupported by the binder.
Common situations: Overly ambitious DTOs with slices of nested complex types in multipart endpoints; reusing JSON-oriented structs (where UnmarshalJSON handles complex shapes) for multipart binding.
Related errors
AI-assisted analysis of gofr-dev/gofr@187eb24962 (2026-09-01).
Data as JSON: /api/errors/e5ee2854fdac6789.
Report an issue: GitHub.