{"record":{"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":"http","errorClass":"actix_multipart::Error","httpStatus":400,"severity":"error","filePath":"actix-multipart/src/error.rs","lineNumber":91,"sourceCode":"    #[display(\"Stream is not consumed\")]\n    NotConsumed,\n\n    /// Form field handler raised error.\n    #[display(\"An error occurred processing field '{name}': {source}\")]\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    }\n}\n","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/actix/actix-web/blob/7ae209e4a4f3c8df61cacb9c2d3b8ef28ebda0d6/actix-multipart/src/error.rs#L73-L109","documentation":"Error::MissingField(String) is raised in FieldGroupReader::from_state for the plain T impl (form/mod.rs:190) when, after consuming the whole multipart stream, the state map does not contain an entry for a required (non-Option) field. It means no part with that name was ever sent, so construction of the struct fails with a 400 Bad Request. Option<T> fields never trigger it because they default to None.","triggerScenarios":"A client submits a multipart form that omits a part the struct declares as a required T: FieldReader. For struct { title: Text<String>, file: TempFile }, a request with only the file part yields MissingField(\"title\").","commonSituations":"Frontend form missing a required input; field name typo between client and server; conditional form fields not sent; renaming a Rust field without updating #[multipart(rename)] or the client.","solutions":["Make the field optional: Option<T> so an absent part yields None instead of an error.","Ensure the client actually sends a part with the exact expected name (mind #[multipart(rename = \"...\")] mappings).","Provide a clearer error to the client via MultipartFormConfig::error_handler."],"exampleFix":"// before\nstruct Upload { title: Text<String>, file: TempFile } // missing title => 400\n\n// after\nstruct Upload { title: Option<Text<String>>, file: TempFile }","handlingStrategy":"validation","validationCode":"// Ensure the client sends all required parts; on the server make optional\nstruct Form {\n    title: Option<Text<String>>, // absent => None, no error\n    file: TempFile,             // still required\n}","typeGuard":null,"tryCatchPattern":"match form_result {\n    Err(e) => {\n        if let Some(actix_multipart::MultipartError::MissingField(name)) =\n            e.as_error::<actix_multipart::MultipartError>()\n        {\n            return HttpResponse::BadRequest().body(format!(\"missing field: {name}\"));\n        }\n        return Err(e);\n    }\n    Ok(form) => handle(form),\n}","preventionTips":["Model genuinely optional inputs as Option<T>.","Keep field names in sync with #[multipart(rename)].","Use MultipartFormConfig::error_handler for uniform error responses."],"tags":["multipart","form-data","actix-multipart","validation"],"backgroundTag":null,"analyzedSha":"7ae209e4a4f3c8df61cacb9c2d3b8ef28ebda0d6","analyzedAt":"2026-08-09T01:01:40.926Z","contentChangedAt":"2026-08-09T01:01:40.926Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}