dbt-labs/dbt-core · error · syn::Error
Failed to parse value of `{field}` as string.
Error message
Failed to parse value of `{field}` as string. What it means
Raised by the `parse_string` helper in crates/dbt-runtime-macros/src/entry.rs when a string-valued attribute option — `name`, `flavor`, or `unhandled_panic` (per the setters `set_name`, `set_flavor`, `set_unhandled_panic`) — is given a literal that is neither a string literal nor a verbatim token, e.g. an integer or bool literal. The macro rejects it at expansion time naming the offending field.
Source
Thrown at crates/dbt-runtime-macros/src/entry.rs:286
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."),
)),
}
}
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())View on GitHub (pinned to 0267ce9170)
Solutions
- Quote the value: `flavor = "multi_thread"`, `name = "my_task"`, `unhandled_panic = "abort_runtime"`.
- For `unhandled_panic`, use the string literal form of the enum value, not a bare bool or identifier.
- If a codegen tool emits the attribute, ensure string fields are emitted as quoted literals.
Example fix
// before
#[dbt_runtime::main(flavor = multi_thread)]
async fn main() { /* ... */ }
// after
#[dbt_runtime::main(flavor = "multi_thread")]
async fn main() { /* ... */ } Defensive patterns
Strategy: validation
Validate before calling
// String options (name, flavor, unhandled_panic) require quoted literals.
#[dbt_runtime::main(
name = "svc",
flavor = "multi_thread",
)]
async fn main() {} Prevention
- Always quote string-valued attribute options; bare identifiers like `flavor = multi_thread` fail.
- unhandled_panic takes a string value like "abort_runtime", not a bool.
- If attributes are generated, validate that string fields are emitted with quotes.
When it happens
Trigger: Writing `name = 42`, `flavor = multi_thread` (unquoted identifier) or `unhandled_panic = true` in the attribute; anything that is not syn::Lit::Str or syn::Lit::Verbatim reaching `parse_string`.
Common situations: Forgetting quotes around enum-like values (`flavor = multi_thread` instead of `flavor = "multi_thread"`); passing a boolean to unhandled_panic instead of the string `"abort_runtime"`; templated attributes substituting unquoted values.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Failed to parse value of `{field}` as integer.
- Failed to parse value of `{field}` as integer: {e}
- The `start_paused` option requires the `current_thread` runt
- The `unhandled_panic` option requires the `current_thread` r
- Failed to parse value of `{field}` as path.
AI-assisted analysis of dbt-labs/dbt-core@0267ce9170 (2026-09-07).
Data as JSON: /api/errors/2ff47ffce0e69de1.
Report an issue: GitHub.