tokio-rs/tokio · error · syn::Error

Failed to parse value of `{field}` as string.

Error message

Failed to parse value of `{field}` as string.

What it means

Compile-time error from `parse_string`'s `_` arm. The attribute value for a string-typed field is neither `syn::Lit::Str` nor `syn::Lit::Verbatim`. It backs the `name`, `flavor`, and `unhandled_panic` fields (see `set_name`, `set_flavor`, `set_unhandled_panic` in entry.rs).

Source

Thrown at tokio-macros/src/entry.rs:276

            Err(e) => Err(syn::Error::new(
                span,
                format!("Failed to parse value of `{field}` as integer: {e}"),
            )),
        },
        _ => Err(syn::Error::new(
            span,
            format!("Failed to parse value of `{field}` as integer."),
        )),
    }
}

fn parse_string(int: syn::Lit, span: Span, field: &str) -> Result<String, syn::Error> {
    match int {
        syn::Lit::Str(s) => Ok(s.value()),
        syn::Lit::Verbatim(s) => Ok(s.to_string()),
        _ => Err(syn::Error::new(
            span,
            format!("Failed to parse value of `{field}` as string."),
        )),
    }
}

fn parse_path(lit: syn::Lit, span: Span, field: &str) -> Result<Path, syn::Error> {
    match lit {
        syn::Lit::Str(s) => {
            let err = syn::Error::new(
                span,
                format!(
                    "Failed to parse value of `{}` as path: \"{}\"",
                    field,
                    s.value()
                ),
            );
            s.parse::<syn::Path>().map_err(|_| err.clone())
        }
        _ => Err(syn::Error::new(

View on GitHub (pinned to 625954f365)

Solutions

  1. Quote the value: `#[tokio::main(flavor = "multi_thread")]`.
  2. For `unhandled_panic`, use `"ignore"` or `"shutdown_runtime"` as a string.
  3. Confirm the field name is spelled exactly (`flavor`, `name`, `unhandled_panic`).

Example fix

// before
#[tokio::main(flavor = 5)]
async fn main() {}

// after
#[tokio::main(flavor = "multi_thread")]
async fn main() {}
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: `#[tokio::main(flavor = 5)]` (int), `flavor = true` (bool), or `flavor = 'a'` (char). Any non-string-literal value where the macro expects a string.

Common situations: Forgetting to quote the flavor value (`flavor = multi_thread` reads as a path, not a string — that hits a different path); passing a bool/number for `name` or `unhandled_panic`; copy-paste from a language where enum-like values are unquoted.

Understand the failure class

Related errors


AI-assisted analysis of tokio-rs/tokio@625954f365 (2026-08-11). Data as JSON: /api/errors/39923bf0580002c9. Report an issue: GitHub.