{"id":"a7111b5aeb4fe0d6","repo":"actix/actix-web","slug":"duplicate-field-found-0","errorCode":null,"errorMessage":"Duplicate field found: {_0}","messagePattern":"Duplicate field found: (.+?)","errorType":"exception","errorClass":"actix_multipart::Error","httpStatus":400,"severity":"error","filePath":"actix-multipart/src/error.rs","lineNumber":82,"sourceCode":"    Parse(ParseError),\n\n    /// HTTP payload error.\n    #[display(\"Payload error\")]\n    Payload(PayloadError),\n\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 {","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/actix/actix-web/blob/937960ca67f20e14ffe2a075bf6d4593502be12c/actix-multipart/src/error.rs#L64-L100","documentation":"MultipartError::DuplicateField(String) (multipart/error.rs:82-84) is returned by the MultipartForm extractor (form/mod.rs:89-92 and 168-172) when the same form field name is submitted more than once AND that field's duplicate_field policy is DuplicateField::Deny. It maps to HTTP 400 BadRequest via the ResponseError impl (error.rs:98-106). Only affects structs using the #[multipart(duplicate_field = \"deny\")] attribute.","triggerScenarios":"A multipart/form-data POST contains two parts with the same Content-Disposition name (e.g. two 'email' fields), and the handler struct declared that field as a scalar type (T or Option<T>) with duplicate_field=deny. The FieldGroupReader for T/Option<T> hits the Deny branch.","commonSituations":"Frontend bug submitting the same field twice, duplicate file inputs, or a misconfigured form. Switching a field from Vec<T> to T changes a previously-tolerant handler into a strict one.","solutions":["If duplicates are legitimate, type the field as Vec<T> (always allows duplicates) or set duplicate_field to \"ignore\"/\"replace\".","If duplicates are invalid, fix the client to send the field exactly once.","Inspect the raw multipart body to find which field name is duplicated."],"exampleFix":"// before: scalar field rejects duplicates\n#[derive(MultipartForm)]\nstruct Form { #[multipart(limit = \"1KiB\")] email: String }\n\n// after: accept duplicates, keep the last\n#[derive(MultipartForm)]\nstruct Form {\n    #[multipart(limit = \"1KiB\", duplicate_field = \"replace\")]\n    email: String,\n}","handlingStrategy":"validation","validationCode":"// On the client, ensure each non-list field is sent exactly once.\n// Inspect the FormData before submit:\nfunction countFields(form, name) {\n  return [...form.getAll(name)].length;\n}\nif (countFields(form, 'email') > 1) { /* dedupe or warn */ }","typeGuard":null,"tryCatchPattern":"// In the handler, the MultipartForm extractor returns actix_web::Error (400).\nasync fn upload(MultipartForm(form): MultipartForm<Form>) -> impl Responder {\n    HttpResponse::Ok().body(\"ok\")\n}\n// duplicate field -> 400 BadRequest with the field name in the error body","preventionTips":["Type list-valued fields as Vec<T> if duplicates are legitimate.","Set duplicate_field to \"ignore\" or \"replace\" when only the last value matters.","Use duplicate_field=deny only when strictness is required, and surface the field name to the user."],"tags":["multipart","form","actix-multipart","validation"],"analyzedSha":"937960ca67f20e14ffe2a075bf6d4593502be12c","analyzedAt":"2026-08-06T01:15:46.978Z","schemaVersion":2}