actix / actix/actix-web

[actix-multipart] Generic "Payload error" when request exceeds size limit

Abierto
#4,168 4 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Rust
Estrellas
24.8k
Forks
1.9k
Merge medio
23 h 10 min
PR fusionados (30 d)
26

Descripción

## Expected Behavior

The error message should describe the nature of the "payload error", such as "payload reached size limit" or "can not decode content-encoding".

## Current Behavior

The plaintext error that appears to users is not actionable.

## Possible Solution

Looking at the [`MultipartError`](https://docs.rs/actix-multipart/latest/actix_multipart/enum.MultipartError.html) enum, it seems the relevant details do exist on the `Payload` case, but the `display` attribute doesn't include them.

~~The simplest fix would probably be to add `: {_0}` to the end of the `display` attribute for this and other affected cases (such as `Parse`), such as in [this playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=4ea06803e4731fa7f8ad2fd016010445). The `DuplicateField`, `MissingField`, and `UnknownField` cases already do something similar. I can draft a PR for this if need be.~~
EDIT: This patch was rejected at https://github.com/actix/actix-web/pull/4186#pullrequestreview-4998119280 and reverted in 6a1feec593b9ecdfb6066b471582c3023b595141.

Alternatively, a custom [`error_response`](https://docs.rs/actix-web/latest/actix_web/error/trait.ResponseError.html#method.error_response) method at https://docs.rs/actix-multipart/latest/src/actix_multipart/error.rs.html#99 could work: one that walks the error tree to respond with something reasonable, even in cases where the `Display` impl must remain incomplete per [official Rust idioms and guidelines](https://doc.rust-lang.org/stable/std/error/trait.Error.html#error-source).

In the meantime, users can work around this by `match`-ing against the error in a custom handler, and patch the output text that way.

## Steps to Reproduce (for bugs)

1. Set up an actix-web service with an endpoint that uses the `actix_multipart::form::MultipartForm` extractor.
2. Try uploading a file that is slightly too large.
3. Observe strange error.

See also this minimal repro: https://git.average.name/AverageHelper/actix_web_multipart_error_display_repro

## Context

I'm trying to handle small image uploads for e.g. profile pictures, which typically don't need to be bigger than ~1 MiB. But even at the default total limit of 50 MiB, the default error should still be somewhat actionable IMO.

## Your Environment

- Rust Version: rustc 1.98.1 (48a229cea 2026-09-01)
- Actix Web Version: 4.15.0

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.