{"id":"a5857aec83b3542c","repo":"actix/actix-web","slug":"could-not-parse-size-limit","errorCode":null,"errorMessage":"Could not parse size limit `{}`: {}","messagePattern":"Could not parse size limit `(.+?)`: (.+?)","errorType":"exception","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"actix-multipart-derive/src/lib.rs","lineNumber":99,"sourceCode":"    };\n\n    let attrs = match MultipartFormAttrs::from_derive_input(&input) {\n        Ok(attrs) => attrs,\n        Err(err) => return err.write_errors().into(),\n    };\n\n    // Parse the field attributes\n    let parsed = match fields\n        .named\n        .iter()\n        .map(|field| {\n            let rust_name = field.ident.as_ref().unwrap();\n            let attrs = FieldAttrs::from_field(field).map_err(|err| err.write_errors())?;\n            let serialization_name = attrs.rename.unwrap_or_else(|| rust_name.to_string());\n\n            let limit = match attrs.limit.map(|limit| match limit.parse::<ByteSize>() {\n                Ok(ByteSize(size)) => Ok(usize::try_from(size).unwrap()),\n                Err(err) => Err(syn::Error::new(\n                    field.ident.as_ref().unwrap().span(),\n                    format!(\"Could not parse size limit `{}`: {}\", limit, err),\n                )),\n            }) {\n                Some(Err(err)) => return Err(compile_err(err)),\n                limit => limit.map(Result::unwrap),\n            };\n\n            Ok(ParsedField {\n                serialization_name,\n                rust_name,\n                limit,\n                ty: &field.ty,\n            })\n        })\n        .collect::<Result<Vec<_>, TokenStream>>()\n    {\n        Ok(attrs) => attrs,","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/actix/actix-web/blob/937960ca67f20e14ffe2a075bf6d4593502be12c/actix-multipart-derive/src/lib.rs#L81-L117","documentation":"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.","triggerScenarios":"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.","commonSituations":"Typos in units, mixing case (`mb` vs `MB` vs `MiB`), or pasting a human string instead of a machine-parseable size.","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."],"exampleFix":"// before\n#[derive(MultipartForm)]\nstruct Form {\n    #[multipart(limit = \"ten mb\")]\n    file: Field,\n}\n\n// after\n#[derive(MultipartForm)]\nstruct Form {\n    #[multipart(limit = \"10MiB\")]\n    file: Field,\n}","handlingStrategy":"validation","validationCode":"// Validate a size string with bytesize before committing it to source.\nuse bytesize::ByteSize;\nfn valid_limit(s: &str) -> bool {\n    s.parse::<ByteSize>().is_ok()\n}\n// assert!(valid_limit(\"10MiB\"));\n// assert!(!valid_limit(\"ten mb\"));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["rust","actix","actix-multipart","macro","compile-time","configuration"],"analyzedSha":"937960ca67f20e14ffe2a075bf6d4593502be12c","analyzedAt":"2026-08-06T01:15:46.978Z","schemaVersion":2}