{"record":{"id":"f18d94e8c62b7854","repo":"actix/actix-web","slug":"duplicate-field-found-0-f18d94","errorCode":null,"errorMessage":"Duplicate field found \"{_0}\"","messagePattern":"Duplicate field found \"(.+?)\"","errorType":"validation","errorClass":"Error","httpStatus":400,"severity":"warning","filePath":"actix-multipart/src/error.rs","lineNumber":86,"sourceCode":"    /// 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\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,","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/actix/actix-web/blob/c215607f4b6e9ba9accff4a949a33c98f218db20/actix-multipart/src/error.rs#L68-L104","documentation":"This is `actix_multipart::form::Error::DuplicateField(String)` raised by actix-multipart's typed form deserialization (`MultipartForm`). It occurs when the struct field is annotated to deny duplicate fields and the client submits a multipart part with a name that maps to a field that already received a value. The library treats repeated fields as a form-level validation error rather than silently overwriting.","triggerScenarios":"A MultipartForm handler whose struct opts into denying duplicate fields receives two parts with the same field name during `MultipartForm::from_request` processing.","commonSituations":"An HTML form accidentally rendered with duplicated input names, a client script appending a file field twice, a user selecting the same file input submitted twice, or retries re-sending a part that was already included.","solutions":["Fix the client so each field name appears at most once in the multipart body.","If multiple values are legitimate, change the struct field to `Vec<T>` so repeats can be collected instead of rejected.","Inspect the field name in the error payload and search your form/template or client code for the duplicated input.","Return a 4xx response to the client with a clear message identifying the duplicated field so they can correct the submission."],"exampleFix":"// before: rejects duplicate uploads\nstruct Upload { files: Vec<MultipartForm<File>> } // field named 'file' sent twice with scalar type\n// after\nderive(MultipartForm)\nstruct Upload { #[multipart(rename = \"file\")] files: Vec<File> } // accepts repeated 'file' parts","handlingStrategy":"validation","validationCode":"// client-side, before submit\nconst names = [...formData.keys()];\nconst dupes = names.filter((n, i) => names.indexOf(n) !== i);\nif (dupes.length) throw new Error(`duplicate multipart fields: ${dupes.join(\", \")}`);","typeGuard":"// server-side: accept repeats explicitly by typing the field as a Vec\nfn accepts_multiple(field_type: &str) -> bool {\n    field_type.starts_with(\"Vec<\")\n}","tryCatchPattern":"// in the handler, MultipartForm extraction failure is a 4xx Error\nasync fn upload(MultipartForm(form): MultipartForm<Upload>) -> impl Responder {\n    /* on DuplicateField the extractor already returns an error response */\n}\n// or map it manually:\nmatch form_result {\n    Err(e) if e.to_string().contains(\"Duplicate field\") => ErrHttpResponse::build(StatusCode::BAD_REQUEST)\n        .insert_header((header::CONTENT_TYPE, \"application/json\"))\n        .body(\"duplicate field in form\"),\n    other => other,\n}","preventionTips":["Ensure every HTML input in a form has a unique name attribute","Guard client scripts against appending the same field/file twice (e.g. re-submit handlers)","Model repeatable fields as Vec<T> in the MultipartForm struct","Add integration tests that post the exact form your client renders"],"tags":["multipart","form-validation","actix-web","duplicate-field"],"backgroundTag":"schema-validation-failed","analyzedSha":"c215607f4b6e9ba9accff4a949a33c98f218db20","analyzedAt":"2026-09-09T15:57:34.010Z","contentChangedAt":"2026-09-09T15:57:34.010Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}