{"record":{"id":"f33f4d3d22242041","repo":"gofr-dev/gofr","slug":"data-length-exceeds-array-capacity","errorCode":null,"errorMessage":"data length exceeds array capacity","messagePattern":"data length exceeds array capacity","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/gofr/http/multipart_file_bind.go","lineNumber":15,"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 {\n\t\t// Check if val is not a struct","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/gofr-dev/gofr/blob/187eb24962502e91f1fee856230670958b66e89c/pkg/gofr/http/multipart_file_bind.go#L1-L33","documentation":"errDataLengthExceeded is returned by setSliceOrArrayValue when the number of multipart values being bound exceeds the capacity of a fixed-size array field in the target struct. Arrays in Go have fixed capacity, so extra values cannot fit.","triggerScenarios":"Binding multiple multipart form/file entries into a field declared as a fixed-size array (e.g. [3]string) while the request carries more than 3 values.","commonSituations":"Client sends more form fields/files than the server's array-based DTO allows; contract drift between client and server where the server shrank the array size.","solutions":["Change the field to a slice ([]string) instead of a fixed-size array to accept any number of values","Increase the array size to accommodate the maximum expected number of values","Enforce the limit client-side or validate the incoming count before binding"],"exampleFix":"// before\ntype Upload struct { Files [3]string }\n// after\ntype Upload struct { Files []string }","handlingStrategy":"validation","validationCode":"if len(r.MultipartForm.Value[field]) > arrayCap { return fmt.Errorf(\"field %s accepts at most %d values\", field, arrayCap) }","typeGuard":"func fitsArray(vals []string, cap int) bool { return len(vals) <= cap }","tryCatchPattern":"if err := bind.Struct(&upload); err != nil { http.Error(w, \"too many values for field\", http.StatusBadRequest); return }","preventionTips":["Prefer slices over fixed-size arrays in request DTOs","Document per-field limits to API clients","Validate incoming value counts in middleware before binding"],"tags":["multipart","binding","array"],"backgroundTag":"data-length-exceeded","analyzedSha":"187eb24962502e91f1fee856230670958b66e89c","analyzedAt":"2026-09-01T20:34:54.554Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}