{"record":{"id":"8b3dab65186a7391","repo":"kataras/iris","slug":"empty-form","errorCode":null,"errorMessage":"empty form","messagePattern":"empty form","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"info","filePath":"context/context.go","lineNumber":2913,"sourceCode":"\t\t}\n\n\t\tif m, ok := err.(schema.MultiError); ok {\n\t\t\tif csrfErr, hasCSRFToken := m[CSRFTokenFormKey]; hasCSRFToken {\n\t\t\t\t_, is := csrfErr.(schema.UnknownKeyError)\n\t\t\t\treturn is\n\n\t\t\t}\n\t\t}\n\n\t\treturn false\n\t}\n\n\t// ErrEmptyForm is returned by\n\t// - `context#ReadForm`\n\t// - `context#ReadQuery`\n\t// - `context#ReadBody`\n\t// when the request data (form, query and body respectfully) is empty.\n\tErrEmptyForm = errors.New(\"empty form\")\n\n\t// ErrEmptyFormField reports whether a specific field exists but it's empty.\n\t// Usage: errors.Is(err, ErrEmptyFormField)\n\t// See postValue method. It's only returned on parsed post value methods.\n\tErrEmptyFormField = errors.New(\"empty form field\")\n\n\t// ConnectionCloseErrorSubstr if at least one of the given\n\t// substrings are found in a net.OpError:os.SyscallError error type\n\t// on `IsErrConnectionReset` then the function will report true.\n\tConnectionCloseErrorSubstr = []string{\n\t\t\"broken pipe\",\n\t\t\"connection reset by peer\",\n\t}\n\n\t// IsErrConnectionClosed reports whether the given \"err\"\n\t// is caused because of a broken connection.\n\tIsErrConnectionClosed = func(err error) bool {\n\t\tif err == nil {","sourceCodeStart":2895,"sourceCodeEnd":2931,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/context/context.go#L2895-L2931","documentation":"ErrEmptyForm is returned by Context.ReadForm, Context.ReadQuery and Context.ReadBody when the request data being read (form body, URL query, or raw body respectively) is empty, so there is nothing to decode into the target struct. It is a sentinel error that callers can detect with errors.Is.","triggerScenarios":"Calling ReadQuery when the request URL has no query parameters; calling ReadForm on a request with no form/body payload; calling ReadBody when the request body is empty (e.g. GET with no body, or Content-Length 0).","commonSituations":"GET requests whose handlers call ReadForm/ReadBody although no payload was sent; clients that send query params on a different HTTP method or URL than expected; HTML forms submitted without any filled fields; wrong Content-Type so the body is not parsed as form data.","solutions":["Handle the sentinel explicitly with errors.Is(err, iris.ErrEmptyForm) and either bind to zero-value defaults or return 400.","Check that the client actually sends data (query string present, non-empty body, correct Content-Type: application/x-www-form-urlencoded or multipart).","For GET endpoints, prefer ReadQuery and verify the URL includes the expected parameters.","Only require form data when the route semantically needs it; make empty input an allowed case in your handler."],"exampleFix":"// before\nvar req FilterRequest\nif err := ctx.ReadQuery(&req); err != nil {\n    ctx.StopWithStatus(400) // fails on empty query string\n    return\n}\n// after\nvar req FilterRequest\nif err := ctx.ReadQuery(&req); err != nil {\n    if errors.Is(err, iris.ErrEmptyForm) {\n        req = FilterRequest{Page: 1, Limit: 20} // sensible defaults\n    } else {\n        ctx.StopWithStatus(400)\n        return\n    }\n}","handlingStrategy":"validation","validationCode":"var req FilterRequest\nif ctx.Request().URL.RawQuery == \"\" && ctx.Request().ContentLength == 0 {\n    req = FilterRequest{Page: 1, Limit: 20} // defaults, skip ReadQuery/ReadForm\n} else if err := ctx.ReadQuery(&req); err != nil { /* handle */ }","typeGuard":null,"tryCatchPattern":"var req FilterRequest\nerr := ctx.ReadForm(&req)\nif err != nil {\n    if errors.Is(err, iris.ErrEmptyForm) {\n        // empty payload: use zero-value/defaults, do not fail\n    } else {\n        ctx.StopWithStatus(iris.StatusBadRequest)\n        return\n    }\n}","preventionTips":["Match the read API to the data source: ReadQuery for query strings, ReadForm for form bodies, ReadBody for raw bodies.","Confirm the client sends a non-empty payload and the correct Content-Type before parsing.","Treat ErrEmptyForm as an expected case for optional-parameter endpoints, not a 500.","Use errors.Is to detect the sentinel rather than comparing error strings."],"tags":["form","request-body","validation","iris"],"backgroundTag":"empty-request-payload","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}