{"record":{"id":"66ac7be016ef8317","repo":"tokio-rs/tokio","slug":"failed-to-parse-value-of-field-as-integer","errorCode":null,"errorMessage":"Failed to parse value of `{field}` as integer.","messagePattern":"Failed to parse value of `(.+?)` as integer\\.","errorType":"validation","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"tokio-macros/src/entry.rs","lineNumber":265,"sourceCode":"            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    }\n}\n\nfn parse_path(lit: syn::Lit, span: Span, field: &str) -> Result<Path, syn::Error> {\n    match lit {\n        syn::Lit::Str(s) => {","sourceCodeStart":247,"sourceCodeEnd":283,"githubUrl":"https://github.com/tokio-rs/tokio/blob/625954f365727668cb02d04172b34f1149637728/tokio-macros/src/entry.rs#L247-L283","documentation":"Compile-time error emitted by the `parse_int` helper inside the `#[tokio::main]`/`#[tokio::test]` proc-macros. It fires from the `_` arm: the attribute value that must be an integer is not a `syn::Lit::Int`. The only configuration field routed through `parse_int` is `worker_threads` (see `set_worker_threads` calling `parse_int(..., \"worker_threads\")` in entry.rs:138). The sibling arm (`base10_parse` failure) carries the underlying parse message; this message is the literal-shape mismatch.","triggerScenarios":"Writing `#[tokio::main(worker_threads = \"8\")]` (a string literal), `worker_threads = 8.0` (a float), `worker_threads = true` (a bool), or `worker_threads = 'a'` (a char). Any token for `worker_threads` that is not an integer literal.","commonSituations":"Copying a thread-count value quoted as a string from a config file or doc snippet; pasting a float because the source used `8.0`; confusing the macro syntax with runtime `Builder::worker_threads(n)` where `n` is a variable (macros require literals, not identifiers).","solutions":["Pass an unquoted positive integer literal: `#[tokio::main(flavor = \"multi_thread\", worker_threads = 8)]`.","Do not use a Rust `const`/variable — proc-macro attributes only accept literals; if you need runtime values, build the runtime manually with `tokio::runtime::Builder`.","Double-check there is no `f`/`.`/quotes/suffix on the number."],"exampleFix":"// before\n#[tokio::main(worker_threads = \"8\")]\nasync fn main() {}\n\n// after\n#[tokio::main(flavor = \"multi_thread\", worker_threads = 8)]\nasync fn main() {}","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass only unquoted positive integer literals to `worker_threads` (e.g. `worker_threads = 8`).","Proc-macro attributes only accept literals — never a `const`, `let`, or expression; switch to `runtime::Builder` for runtime-computed thread counts.","Keep one canonical, copy-pasteable `#[tokio::main(...)]` snippet in the repo to avoid drift."],"tags":["rust","tokio","macros","configuration","compile-time"],"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"}