block/buzz · error · syn::Error

duplicate `name` argument

Error message

duplicate `name` argument

What it means

buzz-datastore-tracing's #[datastore_span] proc macro parses its attribute arguments with a hand-written syn Parse impl. It accepts name = "lit", system = "lit", and fields(...) exactly once each; a second `name = ...` key produces this compile-time syn::Error on the duplicate key's span. It is a compile error in the crate using the macro, not a runtime failure.

Source

Thrown at crates/buzz-datastore-tracing/src/lib.rs:28

struct DatastoreArgs {
    name: LitStr,
    system: LitStr,
    fields: Option<TokenStream2>,
}

impl Parse for DatastoreArgs {
    fn parse(input: ParseStream<'_>) -> Result<Self> {
        let mut name = None;
        let mut system = None;
        let mut fields = None;

        while !input.is_empty() {
            let key: Ident = input.parse()?;
            match key.to_string().as_str() {
                "name" => {
                    if name.is_some() {
                        return Err(Error::new(key.span(), "duplicate `name` argument"));
                    }
                    input.parse::<Token![=]>()?;
                    name = Some(input.parse()?);
                }
                "system" => {
                    if system.is_some() {
                        return Err(Error::new(key.span(), "duplicate `system` argument"));
                    }
                    input.parse::<Token![=]>()?;
                    system = Some(input.parse()?);
                }
                "fields" => {
                    if fields.is_some() {
                        return Err(Error::new(key.span(), "duplicate `fields` argument"));
                    }
                    let content;
                    parenthesized!(content in input);
                    fields = Some(content.parse()?);

View on GitHub (pinned to eed74bde2f)

Solutions

  1. Delete the duplicate `name = ...` — each argument may appear at most once per attribute.
  2. Use `cargo check -p buzz-db` (or the crate that failed) to confirm the span error is gone.
  3. Keep the canonical ordering name → system → fields used across the codebase to make duplicates obvious in review.

Example fix

// before
#[datastore_span(name = "fetch_user", system = "postgresql", name = "fetch_user_v2")]
async fn fetch_user(...) {}

// after
#[datastore_span(name = "fetch_user", system = "postgresql")]
async fn fetch_user(...) {}
Defensive patterns

Strategy: validation

Validate before calling

// no runtime API — validate by compiling: `cargo check -p buzz-db`
// the macro reports the exact span of the duplicate `name` key

Prevention

When it happens

Trigger: Annotating a function with #[datastore_span(name = "fetch_user", name = "fetch_user_v2", system = "postgresql")] — the second name key trips the duplicate check at crates/buzz-datastore-tracing/src/lib.rs:27-29 during macro expansion, failing compilation of buzz-db (the main consumer).

Common situations: Copy-paste of an existing annotated function followed by editing only the second name value; merge conflicts resolving to both variants of the attribute; IDE auto-completing the key again.

Related errors


AI-assisted analysis of block/buzz@eed74bde2f (2026-08-20). Data as JSON: /api/errors/67a18f1a5cd52fdd. Report an issue: GitHub.