{"record":{"id":"a7111b5aeb4fe0d6","repo":"actix/actix-web","slug":"duplicate-field-found-0","errorCode":null,"errorMessage":"Duplicate field found: {_0}","messagePattern":"Duplicate field found: (.+?)","errorType":"http","errorClass":"actix_multipart::Error","httpStatus":400,"severity":"error","filePath":"actix-multipart/src/error.rs","lineNumber":86,"sourceCode":"    /// HTTP payload error.\n    #[display(\"Payload error: {_0}\")]\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}': {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,","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/actix/actix-web/blob/7ae209e4a4f3c8df61cacb9c2d3b8ef28ebda0d6/actix-multipart/src/error.rs#L68-L104","documentation":"Error::DuplicateField(String) is raised by the MultipartForm extractor (form/mod.rs:90 and :169) when a second part with the same field name arrives on a struct field configured with #[multipart(duplicate_field = \"deny\")] and the field type is not a Vec. The derive macro wires the Deny policy into handle_field; on collision it returns this error which becomes a 400 Bad Request (error.rs:103). Vec fields ignore the policy and always accumulate.","triggerScenarios":"A client POSTs multipart/form-data containing two parts named identically (e.g. two \"email\" fields) to a handler whose struct uses #[multipart(duplicate_field = \"deny\")] with a non-Vec field. See test_duplicate_field at form/mod.rs:800.","commonSituations":"Browser forms with duplicate input names; a frontend bug re-sending a field; testing duplicate submission; changing a field from single to multi-value without updating the struct.","solutions":["If duplicates are legitimate, change the field type to Vec<T> (which always allows repeats) or Option<Vec<T>>.","Switch the policy to ignore (default, keeps first) or replace (keeps last) via #[multipart(duplicate_field = \"ignore\")] / \"replace\".","If duplicates should be rejected, keep deny and fix the client to send the field only once."],"exampleFix":"// before\n#[derive(MultipartForm)]\n#[multipart(duplicate_field = \"deny\")]\nstruct Form { email: Text<String> } // 2x \"email\" => 400\n\n// after (allow multiple)\n#[derive(MultipartForm)]\nstruct Form { emails: Vec<Text<String>> }","handlingStrategy":"validation","validationCode":"// Declare field multiplicity to match client behaviour\n// duplicates expected -> use Vec; otherwise set an explicit policy\n","typeGuard":"// Choose field type by expected cardinality\nstruct Form {\n    // single, no dups allowed:\n    email: Text<String>,\n    // multiple allowed:\n    tags: Vec<Text<String>>,\n}","tryCatchPattern":"match form_result {\n    Err(actix_web::Error e) if is_duplicate_field(&e) => {\n        return HttpResponse::BadRequest().body(\"field sent more than once\");\n    }\n    _ => { /* ... */ }\n}","preventionTips":["Use Vec<T> when a field may legitimately repeat.","Set #[multipart(duplicate_field)] explicitly so intent is clear.","Validate on the client to avoid sending duplicates for single-valued fields."],"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"}