{"id":"da948f96662b61a2","repo":"actix/actix-web","slug":"required-field-is-missing-0","errorCode":null,"errorMessage":"Required field is missing: {_0}","messagePattern":"Required field is missing: (.+?)","errorType":"exception","errorClass":"actix_multipart::Error","httpStatus":400,"severity":"error","filePath":"actix-multipart/src/error.rs","lineNumber":87,"sourceCode":"\n    /// Stream is not consumed.\n    #[display(\"Stream is not consumed\")]\n    NotConsumed,\n\n    /// Form field handler raised error.\n    #[display(\"An error occurred processing field: {name}\")]\n    Field {\n        name: String,\n        source: actix_web::Error,\n    },\n\n    /// Duplicate field found (for structure that opted-in to denying duplicate fields).\n    #[display(\"Duplicate field found: {_0}\")]\n    #[from(ignore)]\n    DuplicateField(#[error(not(source))] String),\n\n    /// Required field is missing.\n    #[display(\"Required field is missing: {_0}\")]\n    #[from(ignore)]\n    MissingField(#[error(not(source))] String),\n\n    /// Unknown field (for structure that opted-in to denying unknown fields).\n    #[display(\"Unknown field: {_0}\")]\n    #[from(ignore)]\n    UnknownField(#[error(not(source))] String),\n}\n\n/// Return `BadRequest` for `MultipartError`.\nimpl ResponseError for Error {\n    fn status_code(&self) -> StatusCode {\n        match &self {\n            Error::Field { source, .. } => source.as_response_error().status_code(),\n            Error::ContentTypeIncompatible => StatusCode::UNSUPPORTED_MEDIA_TYPE,\n            _ => StatusCode::BAD_REQUEST,\n        }\n    }","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/actix/actix-web/blob/937960ca67f20e14ffe2a075bf6d4593502be12c/actix-multipart/src/error.rs#L69-L105","documentation":"MultipartError::MissingField(String) (multipart/error.rs:87-89) is returned by the FieldGroupReader for a plain scalar type T in form/mod.rs:186-191 when from_state cannot find the field name in the accumulated state — i.e. the client never sent a part with that name. It maps to HTTP 400 BadRequest. Only plain T fields (not Option<T> or Vec<T>) are required; Option and Vec default to None/empty.","triggerScenarios":"A multipart/form-data submission omits a part whose name matches a non-Option, non-Vec field of the handler struct. The extractor iterates all incoming fields, none populate the required name, and from_state returns MissingField.","commonSituations":"Frontend form missing a required input, a file upload where the file input had no name attribute, or a renamed backend field that the client was not updated to match.","solutions":["Make the field optional: change T to Option<T> if the part is legitimately skippable.","Ensure the client sends a part with the exact name (Content-Disposition: form-data; name=\"<field>\").","Verify the field name in the struct matches the form input name attribute exactly (case-sensitive)."],"exampleFix":"// before: required scalar\n#[derive(MultipartForm)]\nstruct Form { avatar: TempFile }\n\n// after: optional\n#[derive(MultipartForm)]\nstruct Form { avatar: Option<TempFile> }","handlingStrategy":"validation","validationCode":"// Client-side: verify all required fields are present before submit.\nconst required = ['username', 'avatar'];\nconst fd = new FormData(form);\nconst missing = required.filter(f => !fd.has(f));\nif (missing.length) { alert('Missing: ' + missing.join(', ')); return }","typeGuard":null,"tryCatchPattern":"// The extractor yields 400 MissingField; map it to a friendly message.\nasync fn handler(MultipartForm(form): MultipartForm<Form>) -> Result<HttpResponse, Error> {\n    Ok(HttpResponse::Ok().finish())\n}\n// wrap with a custom error handler that downcasts to MultipartError::MissingField\n// to render the missing field name in the 400 response.","preventionTips":["Type genuinely-optional fields as Option<T> instead of T.","Keep the HTML form input name attributes in sync with the Rust struct field names.","Validate required inputs on the client and again on the server."],"tags":["multipart","form","actix-multipart","validation"],"analyzedSha":"937960ca67f20e14ffe2a075bf6d4593502be12c","analyzedAt":"2026-08-06T01:15:46.978Z","schemaVersion":2}