dbt-labs/dbt-core · error · syn::Error

Failed to parse value of `{field}` as integer: {e}

Error message

Failed to parse value of `{field}` as integer: {e}

What it means

Raised by the `parse_int` helper in crates/dbt-runtime-macros/src/entry.rs (called from setters like `set_worker_threads`) when an integer-valued attribute option (e.g. `worker_threads = ...`) is a literal of type syn::Lit::Int but its digits cannot be parsed into a `usize` (e.g. overflow of usize, or an invalid base-10 integer form). The underlying parse error is included in the message.

Source

Thrown at crates/dbt-runtime-macros/src/entry.rs:270

            (_, None) => None,
        };

        Ok(FinalConfig {
            name: self.name.clone(),
            crate_name: self.crate_name.clone(),
            flavor,
            worker_threads,
            start_paused,
            unhandled_panic,
        })
    }
}

fn parse_int(int: syn::Lit, span: Span, field: &str) -> Result<usize, syn::Error> {
    match int {
        syn::Lit::Int(lit) => match lit.base10_parse::<usize>() {
            Ok(value) => Ok(value),
            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."),

View on GitHub (pinned to 0267ce9170)

Solutions

  1. Reduce the value so it fits in a usize (e.g. a realistic thread count like `worker_threads = 8`).
  2. Read the wrapped inner parse error in the message to see why the literal was rejected (overflow vs format) and fix accordingly.
  3. For dynamic configuration, take worker count from an env var at runtime instead of baking an overflowing literal into the attribute.

Example fix

// before
#[dbt_runtime::main(worker_threads = 99999999999999999999999)]
async fn main() { /* ... */ }

// after
#[dbt_runtime::main(flavor = "multi_thread", worker_threads = 8)]
async fn main() { /* ... */ }
Defensive patterns

Strategy: validation

Validate before calling

// Check the literal fits in usize before placing it in the attribute.
const WORKER_THREADS: u64 = 8;
const _: () = assert!(WORKER_THREADS <= usize::MAX as u64, "worker_threads overflows usize");

Prevention

When it happens

Trigger: Passing `worker_threads = 999999999999999999999999` (exceeds usize range) or another syntactically valid integer literal whose value overflows `usize::from_str_radix`-style base-10 parsing. Called during macro attribute parsing via `set_worker_threads`.

Common situations: Hand-writing a huge or negative-looking worker thread count; generating attribute values programmatically (codegen) that overflow usize; copy-pasting a value with stray characters that syn accepts as an Int literal but base10_parse rejects.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of dbt-labs/dbt-core@0267ce9170 (2026-09-07). Data as JSON: /api/errors/c8c16b5f3cbd582a. Report an issue: GitHub.