kataras/iris · error
empty form field
Error message
empty form field
What it means
ErrEmptyFormField is a sentinel error (use with errors.Is) returned by the Context's post-value methods (PostValue*, backed by postValue) when a specific form field exists in the parsed request body but its value is an empty string. It is only produced by the parsed post-value methods, not by generic form/query lookups. It lets callers distinguish 'field present but empty' from 'field absent' (which returns the zero value / ErrEmptyForm for the whole body).
Source
Thrown at context/context.go:2918
return is
}
}
return false
}
// ErrEmptyForm is returned by
// - `context#ReadForm`
// - `context#ReadQuery`
// - `context#ReadBody`
// when the request data (form, query and body respectfully) is empty.
ErrEmptyForm = errors.New("empty form")
// ErrEmptyFormField reports whether a specific field exists but it's empty.
// Usage: errors.Is(err, ErrEmptyFormField)
// See postValue method. It's only returned on parsed post value methods.
ErrEmptyFormField = errors.New("empty form field")
// ConnectionCloseErrorSubstr if at least one of the given
// substrings are found in a net.OpError:os.SyscallError error type
// on `IsErrConnectionReset` then the function will report true.
ConnectionCloseErrorSubstr = []string{
"broken pipe",
"connection reset by peer",
}
// IsErrConnectionClosed reports whether the given "err"
// is caused because of a broken connection.
IsErrConnectionClosed = func(err error) bool {
if err == nil {
return false
}
if opErr, ok := err.(*net.OpError); ok {
if syscallErr, ok := opErr.Err.(*os.SyscallError); ok {View on GitHub (pinned to 7bedaf55a0)
Solutions
- Check the error with errors.Is(err, context.ErrEmptyFormField) and decide whether an empty value is acceptable for that field.
- Use ctx.PostValueDefault("field", "fallback") (or read via ctx.FormValue/ctx.FormValues and validate yourself) so an empty field yields a default instead of the sentinel error.
- If the whole body may be empty, also guard errors.Is(err, context.ErrEmptyForm) before inspecting individual fields.
- Validate on the client side (required/minlength attributes) or reject earlier with a middleware that checks required form fields.
Example fix
// before
email, err := ctx.PostValue("email")
if err != nil {
return err
}
// after
email, err := ctx.PostValue("email")
if errors.Is(err, context.ErrEmptyFormField) || errors.Is(err, context.ErrEmptyForm) {
email = "" // or a default / skip optional field
} else if err != nil {
return err
} Defensive patterns
Strategy: validation
Validate before calling
if vals, err := ctx.FormValues(); err == nil {
if v, ok := vals["email"]; !ok || strings.TrimSpace(v[0]) == "" {
// field missing or empty: handle before calling PostValue
}
} Type guard
func isErrEmptyFormField(err error) bool {
return errors.Is(err, context.ErrEmptyFormField) || errors.Is(err, context.ErrEmptyForm)
} Try / catch
v, err := ctx.PostValue("email")
if errors.Is(err, context.ErrEmptyFormField) {
v = "" // treat as optional
} else if err != nil {
ctx.StatusCode(http.StatusBadRequest)
return
} Prevention
- Use PostValueDefault for optional fields so empty values fall back instead of erroring.
- Distinguish missing-key vs empty-value handling in your form contract and document it.
- Add client-side required/maxlength validation to reduce empty submissions.
- Always compare with errors.Is, never ==, since the error may be wrapped.
When it happens
Trigger: Calling ctx.PostValue("field"), ctx.PostValueInt, ctx.PostValueInt64, ctx.PostValueFloat64, ctx.PostValueBool, ctx.PostValueTime, etc. when the multipart/urlencoded body was parsed and contains the field key but the client submitted it with an empty value (e.g. <input name="email" value=""> or email=).
Common situations: HTML forms where the user left an optional input blank and the browser still submits the key; API clients sending empty multipart fields; mobile clients serializing every struct field including empty strings; forgetting that PostValue treats empty-string-present differently from a missing key.
Related errors
- compress: response will not be compressed
- precondition failed
- origin not allowed
- ErrEmptyFormField
- compress: request is not compressed
AI-assisted analysis of kataras/iris@7bedaf55a0 (2026-08-30).
Data as JSON: /api/errors/96dc8571ab546b74.
Report an issue: GitHub.