actix/actix-web · warning · Error

Duplicate field found "{_0}"

Error message

Duplicate field found "{_0}"

What it means

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.

Source

Thrown at actix-multipart/src/error.rs:86

    /// HTTP payload error.
    #[display("Payload error")]
    Payload(PayloadError),

    /// Stream is not consumed.
    #[display("Stream is not consumed")]
    NotConsumed,

    /// Form field handler raised error.
    #[display("An error occurred processing field \"{name}\"")]
    Field {
        name: String,
        source: actix_web::Error,
    },

    /// Duplicate field found (for structure that opted-in to denying duplicate fields).
    #[display("Duplicate field found \"{_0}\"")]
    #[from(ignore)]
    DuplicateField(#[error(not(source))] String),

    /// Required field is missing.
    #[display("Required field is missing \"{_0}\"")]
    #[from(ignore)]
    MissingField(#[error(not(source))] String),

    /// Unknown field (for structure that opted-in to denying unknown fields).
    #[display("Unknown field \"{_0}\"")]
    #[from(ignore)]
    UnknownField(#[error(not(source))] String),
}

impl ResponseError for Error {
    fn status_code(&self) -> StatusCode {
        match &self {
            Error::Field { source, .. } => source.as_response_error().status_code(),
            Error::ContentTypeIncompatible => StatusCode::UNSUPPORTED_MEDIA_TYPE,
            _ => StatusCode::BAD_REQUEST,

View on GitHub (pinned to c215607f4b)

Solutions

  1. Fix the client so each field name appears at most once in the multipart body.
  2. If multiple values are legitimate, change the struct field to `Vec<T>` so repeats can be collected instead of rejected.
  3. Inspect the field name in the error payload and search your form/template or client code for the duplicated input.
  4. Return a 4xx response to the client with a clear message identifying the duplicated field so they can correct the submission.

Example fix

// before: rejects duplicate uploads
struct Upload { files: Vec<MultipartForm<File>> } // field named 'file' sent twice with scalar type
// after
derive(MultipartForm)
struct Upload { #[multipart(rename = "file")] files: Vec<File> } // accepts repeated 'file' parts
Defensive patterns

Strategy: validation

Validate before calling

// client-side, before submit
const names = [...formData.keys()];
const dupes = names.filter((n, i) => names.indexOf(n) !== i);
if (dupes.length) throw new Error(`duplicate multipart fields: ${dupes.join(", ")}`);

Type guard

// server-side: accept repeats explicitly by typing the field as a Vec
fn accepts_multiple(field_type: &str) -> bool {
    field_type.starts_with("Vec<")
}

Try / catch

// in the handler, MultipartForm extraction failure is a 4xx Error
async fn upload(MultipartForm(form): MultipartForm<Upload>) -> impl Responder {
    /* on DuplicateField the extractor already returns an error response */
}
// or map it manually:
match form_result {
    Err(e) if e.to_string().contains("Duplicate field") => ErrHttpResponse::build(StatusCode::BAD_REQUEST)
        .insert_header((header::CONTENT_TYPE, "application/json"))
        .body("duplicate field in form"),
    other => other,
}

Prevention

When it happens

Trigger: A MultipartForm handler whose struct opts into denying duplicate fields receives two parts with the same field name during `MultipartForm::from_request` processing.

Common situations: 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.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of actix/actix-web@c215607f4b (2026-09-09). Data as JSON: /api/errors/f18d94e8c62b7854. Report an issue: GitHub.