{"record":{"id":"7ffeed7514f97f9e","repo":"tokio-rs/tokio","slug":"failed-to-parse-value-of-field-as-integer-e","errorCode":null,"errorMessage":"Failed to parse value of `{field}` as integer: {e}","messagePattern":"Failed to parse value of `(.+?)` as integer: (.+?)","errorType":"validation","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"tokio-macros/src/entry.rs","lineNumber":260,"sourceCode":"\n        Ok(FinalConfig {\n            name: self.name.clone(),\n            crate_name: self.crate_name.clone(),\n            flavor,\n            worker_threads,\n            start_paused,\n            unhandled_panic,\n        })\n    }\n}\n\nfn parse_int(int: syn::Lit, span: Span, field: &str) -> Result<usize, syn::Error> {\n    match int {\n        syn::Lit::Int(lit) => match lit.base10_parse::<usize>() {\n            Ok(value) => Ok(value),\n            Err(e) => Err(syn::Error::new(\n                span,\n                format!(\"Failed to parse value of `{field}` as integer: {e}\"),\n            )),\n        },\n        _ => Err(syn::Error::new(\n            span,\n            format!(\"Failed to parse value of `{field}` as integer.\"),\n        )),\n    }\n}\n\nfn parse_string(int: syn::Lit, span: Span, field: &str) -> Result<String, syn::Error> {\n    match int {\n        syn::Lit::Str(s) => Ok(s.value()),\n        syn::Lit::Verbatim(s) => Ok(s.to_string()),\n        _ => Err(syn::Error::new(\n            span,\n            format!(\"Failed to parse value of `{field}` as string.\"),\n        )),\n    }","sourceCodeStart":242,"sourceCodeEnd":278,"githubUrl":"https://github.com/tokio-rs/tokio/blob/625954f365727668cb02d04172b34f1149637728/tokio-macros/src/entry.rs#L242-L278","documentation":"`parse_int` (entry.rs:253) is used for `worker_threads` (and any integer-valued macro option). It requires a `syn::Lit::Int` and a successful `base10_parse::<usize>()`. A literal that parses syntactically as an integer but overflows `usize` (or any non-integer literal) hits this branch, with the underlying parse error interpolated.","triggerScenarios":"Writing `#[tokio::main(worker_threads = 99999999999999999999)]` (overflow) or `#[tokio::main(worker_threads = \"4\")]` (wrong literal kind).","commonSituations":"Passing a value derived from a string literal; very large counts; negative numbers passed as integer literals.","solutions":["Provide a plain integer literal within `usize` range, e.g. `worker_threads = 4`.","Do not quote the value — it must be an integer token, not a string.","If the count comes from configuration, read it at runtime via `Builder::new_multi_thread().worker_threads(n)` instead of the macro."],"exampleFix":"// before — string literal or overflow\n#[tokio::main(worker_threads = \"4\")]\nasync fn main() {}\n\n// after — plain integer literal\n#[tokio::main(worker_threads = 4)]\nasync fn main() {}","handlingStrategy":"validation","validationCode":"// Use a plain integer literal in range of usize for the macro:\n//   #[tokio::main(worker_threads = 4)]\n// For dynamic values, bypass the macro and build manually:\nlet rt = tokio::runtime::Builder::new_multi_thread()\n    .worker_threads(n.clamp(1, 1024))\n    .enable_all()\n    .build()?;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass an unquoted integer literal to integer macro options.","Keep the value within `usize` range and positive.","Use the runtime builder API, not the macro, for computed worker counts."],"tags":["tokio","macros","compile-error","config","invalid-value","parse"],"backgroundTag":null,"analyzedSha":"625954f365727668cb02d04172b34f1149637728","analyzedAt":"2026-08-11T17:46:45.378Z","contentChangedAt":"2026-08-11T17:46:45.378Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}