pydantic/monty · error · syn::Error

missing `#[from_args(name = "...")]` on the struct

Error message

missing `#[from_args(name = "...")]` on the struct

What it means

A compile-time error from the `FromArgs` derive macro. Every struct deriving `FromArgs` must carry `#[from_args(name = "...")]` giving the Python-visible function name, used to build accurate argument-binding error messages. Without it the macro cannot proceed and reports the missing attribute at the call site.

Solutions

  1. Add `#[from_args(name = "function_name")]` with the Python function name the struct binds arguments for
  2. If the attribute was accidentally deleted, restore it from a sibling arg struct
  3. Verify the name string matches the builtin/method name so runtime arg errors read correctly

Example fix

// before
#[derive(FromArgs)]
struct FArgs { x: i64 }

// after
#[derive(FromArgs)]
#[from_args(name = "f")]
struct FArgs { x: i64 }
Defensive patterns

Strategy: validation

Validate before calling

// Every FromArgs struct needs: #[from_args(name = "...")]
// Check the attribute exists before compiling:
// grep -L 'from_args(name' my_args.rs

Prevention

When it happens

Trigger: Deriving `FromArgs` on a struct that has a `#[from_args(...)]` attribute list but no `name = "..."` entry in it, or that has no `#[from_args]` attribute at all where one is required by the style.

Common situations: Copy-pasting a struct definition and trimming the attribute, adding the derive before writing the attribute, or renaming a function without updating the `name` value.

Understand the failure class

Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.

Related errors


AI-assisted analysis of pydantic/monty@adc986b362 (2026-09-13). Data as JSON: /api/errors/dbe4452786eaca30. Report an issue: GitHub.

Appendix: source

Thrown at crates/monty-macros/src/from_args.rs:832

                if bad_arg.is_some() {
                    return Err(meta.error("`bad_arg` and `bad_arg_named` are mutually exclusive"));
                }
                bad_arg = Some(BadArgStyle::Named);
                Ok(())
            } else if meta.path.is_ident("kwargs_not_supported_yet") {
                kwargs_not_supported_yet = true;
                Ok(())
            } else {
                Err(meta.error(
                    "unknown struct attribute; expected `name = \"...\"`, `style = def|clinic|c|c_named|unpack`, \
                     `at_most_total`, `vectorcall`, `kwarg_error_name = \"...\"`, `bad_arg`, `bad_arg_named`, \
                     or `kwargs_not_supported_yet`",
                ))
            }
        })?;
    }
    let name = name.ok_or_else(|| {
        syn::Error::new(
            Span::call_site(),
            "missing `#[from_args(name = \"...\")]` on the struct",
        )
    })?;
    Ok(StructAttrs {
        name,
        style: style.unwrap_or(Style::Clinic),
        at_most_total,
        vectorcall,
        kwarg_error_name,
        bad_arg,
        kwargs_not_supported_yet,
    })
}

#[derive(Default)]
pub(crate) struct FieldAttrs {
    pub(crate) kind: FieldKind,

View on GitHub (pinned to adc986b362)