FuelLabs/fuels-rs · error · syn::Error

missing attribute '{name}'

Error message

missing attribute '{name}'

What it means

Compile-time error from fuels-macros' UniqueNameValues::get_as_lit_str: a required attribute key was not present in the parsed name='value' list. The macro asked for a mandatory string attribute (e.g. 'name' or 'project' on a program binding) and try_get returned None, so the error is emitted on the whole attribute's span.

Source

Thrown at packages/fuels-macros/src/parse_utils/unique_name_values.rs:61

            .map(|name| format!("'{name}'"))
            .join(", ");

        self.name_values
            .keys()
            .filter(|name| !allowed_names.contains(&name.to_string().as_str()))
            .map(|name| {
                Error::new_spanned(
                    name.clone(),
                    format!("attribute '{name}' not recognized. Expected one of: {expected_names}"),
                )
            })
            .validate_no_errors()
    }

    pub fn get_as_lit_str(&self, name: &str) -> syn::Result<&LitStr> {
        let value = self
            .try_get(name)
            .ok_or_else(|| Error::new(self.span, format!("missing attribute '{name}'")))?;

        if let Lit::Str(lit_str) = value {
            Ok(lit_str)
        } else {
            Err(Error::new_spanned(
                value.clone(),
                format!("expected the attribute '{name}' to have a string value"),
            ))
        }
    }

    fn extract_name_values<T: Iterator<Item = MetaNameValue>>(
        name_value_metas: T,
    ) -> syn::Result<Vec<(Ident, Lit)>> {
        let (name_values, name_value_errors): (Vec<_>, Vec<Error>) = name_value_metas
            .into_iter()
            .map(|nv| {
                let ident = nv.path.get_ident().cloned().ok_or_else(|| {

View on GitHub (pinned to d9a250a518)

Solutions

  1. Read the message: it names the exact missing attribute '{name}'.
  2. Add the missing key with a string literal value, e.g. Contract(name="counter", project="../counter").
  3. Check the macro's validation of allowed names (validate_has_no_other_names) to see the full expected attribute set for that command.
  4. Consult the docs/tests for the macro to confirm which keys are required vs optional.

Example fix

// before
setup_program_test!(
    Abigen(contracts = [(name = "counter")])
)
// after
setup_program_test!(
    Abigen(contracts = [(name = "counter", project = "../counter")])
)
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: A program binding or command provides some attributes but omits a mandatory one parsed via get_as_lit_str — e.g. Contract(name="counter") without project=..., or a command where the string-typed key is missing entirely (as opposed to present with a non-string value, which produces the separate 'expected the attribute ... to have a string value' error).

Common situations: Following a partial example that omits the key; SDK upgrades making a previously-optional attribute mandatory; assuming the key has a default.

Related errors


AI-assisted analysis of FuelLabs/fuels-rs@d9a250a518 (2026-08-16). Data as JSON: /api/errors/0be5da0bdd35076a. Report an issue: GitHub.