[actix-multipart] Generic "Payload error" when request exceeds size limit
- Lingua principale
- Rust
- Stelle
- 24.8k
- Fork
- 1.9k
- Merge medio
- 23h 10m
- PR unite (30g)
- 26
Descrizione
## 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
Guida per i contributori
Apri la guida per i contributori
Valutazione
Questa issue non è ancora stata valutata.