gofr-dev/gofr · error

unsupported interface value type

Error message

unsupported interface value type

What it means

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.

Source

Thrown at pkg/gofr/http/multipart_file_bind.go:14

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 {

View on GitHub (pinned to 187eb24962)

Solutions

  1. Replace interface{} fields in the bind target with concrete types (string, int, []byte, etc.)
  2. Pre-scan the struct and drop/skip interface fields before binding, or bind into a dedicated concrete DTO
  3. Handle the error in the bind call and return a clear 400 to the client about the unsupported field type

Example fix

// before
type Upload struct { Metadata interface{} }
// after
type Upload struct { Metadata map[string]string }
Defensive patterns

Strategy: type-guard

Validate before calling

reflect.TypeOf(target).Field(i).Type.Kind() == reflect.Interface // reject before binding

Type guard

func hasInterfaceFields(v any) bool {
  t := reflect.TypeOf(v)
  if t.Kind() == reflect.Ptr { t = t.Elem() }
  if t.Kind() != reflect.Struct { return false }
  for i := 0; i < t.NumField(); i++ {
    if t.Field(i).Type.Kind() == reflect.Interface { return true }
  }
  return false
}

Try / catch

if err := bind.Struct(&upload); err != nil { http.Error(w, err.Error(), http.StatusBadRequest); return }

Prevention

When it happens

Trigger: Defining a bind target struct with an interface{} (or custom interface) field and uploading a multipart file/form to bind into it.

Common situations: 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.

Related errors


AI-assisted analysis of gofr-dev/gofr@187eb24962 (2026-09-01). Data as JSON: /api/errors/1ef5c07c2975c5ce. Report an issue: GitHub.