actix/actix-web · warning · Error

Required field is missing

Error message

Required field is missing "{_0}"

What it means

This is `actix_multipart::form::Error::MissingField(String)` raised by actix-multipart's typed form deserialization (`MultipartForm`). It means a required (non-Option) struct field did not receive a corresponding multipart part in the submitted body. The library cannot construct the target struct, so it fails the request with this validation error.

Solutions

  1. Make the field optional in the struct (`Option<T>`) if the client is allowed to omit it.
  2. Fix the client form so every required field's `name` matches the Rust struct field (or `#[multipart(rename = "...")]`).
  3. Verify the request uses `Content-Type: multipart/form-data` with a proper boundary and that the part name matches exactly (case-sensitive).
  4. Test with curl `-F name=value` to reproduce and confirm which part the server expects.

Example fix

// before
struct Form { title: String } // client sometimes omits 'title'
// after
struct Form { title: Option<String> } // or send the part: curl -F title=hello ...
Defensive patterns

Strategy: validation

Validate before calling

// client-side, before submit
const required = ["title", "file"];
const missing = required.filter((n) => !formData.has(n));
if (missing.length) throw new Error(`missing multipart fields: ${missing.join(", ")}`);

Type guard

// server-side: mark truly-optional fields as Option<T>
fn is_optional<T>(_: &Option<T>) -> bool { true }

Try / catch

match form_result {
    Err(e) if e.to_string().contains("Required field is missing") =>
        ErrHttpResponse::build(StatusCode::BAD_REQUEST).body("missing required form field"),
    other => other,
}

Prevention

When it happens

Trigger: A `#[derive(MultipartForm)]` struct has a non-Option field, and `MultipartForm::from_request` finishes consuming parts without ever seeing a part with that field's name.

Common situations: Client form omitted an input the server requires, the input's `name` attribute does not match the Rust field name, curl/tests built manually without all parts, or the client sent JSON instead of multipart/form-data.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of actix/actix-web@c215607f4b (2026-09-09). Data as JSON: /api/errors/6b80b99367f0b01a. Report an issue: GitHub.

Appendix: source

Thrown at actix-multipart/src/error.rs:91

    #[display("Stream is not consumed")]
    NotConsumed,

    /// Form field handler raised error.
    #[display("An error occurred processing field \"{name}\"")]
    Field {
        name: String,
        source: actix_web::Error,
    },

    /// Duplicate field found (for structure that opted-in to denying duplicate fields).
    #[display("Duplicate field found \"{_0}\"")]
    #[from(ignore)]
    DuplicateField(#[error(not(source))] String),

    /// Required field is missing.
    #[display("Required field is missing \"{_0}\"")]
    #[from(ignore)]
    MissingField(#[error(not(source))] String),

    /// Unknown field (for structure that opted-in to denying unknown fields).
    #[display("Unknown field \"{_0}\"")]
    #[from(ignore)]
    UnknownField(#[error(not(source))] String),
}

impl ResponseError for Error {
    fn status_code(&self) -> StatusCode {
        match &self {
            Error::Field { source, .. } => source.as_response_error().status_code(),
            Error::ContentTypeIncompatible => StatusCode::UNSUPPORTED_MEDIA_TYPE,
            _ => StatusCode::BAD_REQUEST,
        }
    }
}

#[cfg(test)]

View on GitHub (pinned to c215607f4b)