actix/actix-web · error · syn::Error
Could not parse size limit `{}`: {}
Error message
Could not parse size limit `{}`: {} What it means
The `#[multipart(limit = "...")]` field attribute is parsed with the `bytesize` crate (`ByteSize`). At actix-multipart-derive/src/lib.rs:97-102, if the string cannot be parsed as a byte size, the original string and the parse error are shown. Valid forms include numbers with units like `"10MiB"`, `"512KB"`, or a bare number of bytes.
Source
Thrown at actix-multipart-derive/src/lib.rs:99
};
let attrs = match MultipartFormAttrs::from_derive_input(&input) {
Ok(attrs) => attrs,
Err(err) => return err.write_errors().into(),
};
// Parse the field attributes
let parsed = match fields
.named
.iter()
.map(|field| {
let rust_name = field.ident.as_ref().unwrap();
let attrs = FieldAttrs::from_field(field).map_err(|err| err.write_errors())?;
let serialization_name = attrs.rename.unwrap_or_else(|| rust_name.to_string());
let limit = match attrs.limit.map(|limit| match limit.parse::<ByteSize>() {
Ok(ByteSize(size)) => Ok(usize::try_from(size).unwrap()),
Err(err) => Err(syn::Error::new(
field.ident.as_ref().unwrap().span(),
format!("Could not parse size limit `{}`: {}", limit, err),
)),
}) {
Some(Err(err)) => return Err(compile_err(err)),
limit => limit.map(Result::unwrap),
};
Ok(ParsedField {
serialization_name,
rust_name,
limit,
ty: &field.ty,
})
})
.collect::<Result<Vec<_>, TokenStream>>()
{
Ok(attrs) => attrs,View on GitHub (pinned to 937960ca67)
Solutions
- Use an integer byte count, e.g. `#[multipart(limit = "10485760")]`.
- Use an IEC/SI unit recognised by bytesize, e.g. `#[multipart(limit = "10MiB")]` or `#[multipart(limit = "5MB")]`.
- Remove the `limit` attribute to fall back to the global `Limits` default.
Example fix
// before
#[derive(MultipartForm)]
struct Form {
#[multipart(limit = "ten mb")]
file: Field,
}
// after
#[derive(MultipartForm)]
struct Form {
#[multipart(limit = "10MiB")]
file: Field,
} Defensive patterns
Strategy: validation
Validate before calling
// Validate a size string with bytesize before committing it to source.
use bytesize::ByteSize;
fn valid_limit(s: &str) -> bool {
s.parse::<ByteSize>().is_ok()
}
// assert!(valid_limit("10MiB"));
// assert!(!valid_limit("ten mb")); Prevention
- Use IEC units (KiB/MiB/GiB) or bare byte counts for clarity.
- Avoid spaces inside the size string.
- If unsure, omit the limit and rely on the global Limits default.
When it happens
Trigger: Passing a malformed limit such as `#[multipart(limit = "lots")]`, `#[multipart(limit = "10 MB")]` (space inside), or an unrecognised unit like `#[multipart(limit = "5gb")]` depending on bytesize's accepted grammar.
Common situations: Typos in units, mixing case (`mb` vs `MB` vs `MiB`), or pasting a human string instead of a machine-parseable size.
Related errors
- `MultipartForm` can only be derived for structs
- `MultipartForm` can only be derived for a struct with named
- Multiple fields named: `{}`
- invalid service definition, expected #[<method>("<path>")]
- Multiple paths specified! There should be only one.
AI-assisted analysis of actix/actix-web@937960ca67 (2026-08-06).
Data as JSON: /data/errors/a5857aec83b3542c.json.
Report an issue: GitHub.