{"record":{"id":"1ef5c07c2975c5ce","repo":"gofr-dev/gofr","slug":"unsupported-interface-value-type","errorCode":null,"errorMessage":"unsupported interface value type","messagePattern":"unsupported interface value type","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/gofr/http/multipart_file_bind.go","lineNumber":14,"sourceCode":"package http\n\nimport (\n\t\"errors\"\n\t\"io\"\n\t\"mime/multipart\"\n\t\"reflect\"\n\t\"strconv\"\n\n\t\"gofr.dev/pkg/gofr/file\"\n)\n\nvar (\n\terrUnsupportedInterfaceType = errors.New(\"unsupported interface value type\")\n\terrDataLengthExceeded       = errors.New(\"data length exceeds array capacity\")\n\terrUnsupportedKind          = errors.New(\"unsupported kind\")\n\terrSettingValueFailure      = errors.New(\"error setting value at index\")\n\terrNotAStruct               = errors.New(\"provided value is not a struct\")\n\terrUnexportedField          = errors.New(\"cannot set field; it might be unexported\")\n\terrUnsupportedFieldType     = errors.New(\"unsupported type for field\")\n\terrFieldsNotSet             = errors.New(\"no fields were set\")\n)\n\ntype formData struct {\n\tfields map[string][]string\n\tfiles  map[string][]*multipart.FileHeader\n}\n\nfunc (uf *formData) mapStruct(val reflect.Value, field *reflect.StructField) (bool, error) {\n\tvKind := val.Kind()\n\n\tif field == nil {","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/gofr-dev/gofr/blob/187eb24962502e91f1fee856230670958b66e89c/pkg/gofr/http/multipart_file_bind.go#L1-L32","documentation":"errUnsupportedInterfaceType is returned by setInterfaceValue while binding multipart form data into a struct: a field holds an interface value that the binder does not know how to populate from string form data. The multipart binder supports concrete scalar/slice/struct kinds, not arbitrary interface fields.","triggerScenarios":"Defining a bind target struct with an interface{} (or custom interface) field and uploading a multipart file/form to bind into it.","commonSituations":"Using interface{} fields in request structs to 'hold anything'; DTOs shared between JSON and multipart endpoints where JSON tolerates interface fields but multipart binding does not.","solutions":["Replace interface{} fields in the bind target with concrete types (string, int, []byte, etc.)","Pre-scan the struct and drop/skip interface fields before binding, or bind into a dedicated concrete DTO","Handle the error in the bind call and return a clear 400 to the client about the unsupported field type"],"exampleFix":"// before\ntype Upload struct { Metadata interface{} }\n// after\ntype Upload struct { Metadata map[string]string }","handlingStrategy":"type-guard","validationCode":"reflect.TypeOf(target).Field(i).Type.Kind() == reflect.Interface // reject before binding","typeGuard":"func hasInterfaceFields(v any) bool {\n  t := reflect.TypeOf(v)\n  if t.Kind() == reflect.Ptr { t = t.Elem() }\n  if t.Kind() != reflect.Struct { return false }\n  for i := 0; i < t.NumField(); i++ {\n    if t.Field(i).Type.Kind() == reflect.Interface { return true }\n  }\n  return false\n}","tryCatchPattern":"if err := bind.Struct(&upload); err != nil { http.Error(w, err.Error(), http.StatusBadRequest); return }","preventionTips":["Use concrete types in multipart bind targets, never interface{}","Keep separate DTOs for JSON and multipart endpoints","Lint request structs for interface fields"],"tags":["multipart","binding","reflection"],"backgroundTag":"unsupported-bind-type","analyzedSha":"187eb24962502e91f1fee856230670958b66e89c","analyzedAt":"2026-09-01T20:34:54.554Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}