diesel-rs/diesel · error

unknown attribute, expected

Error message

unknown attribute, expected{prefix} `{}`

What it means

Generic error emitted by diesel's attribute parser utilities when an unrecognized attribute key is encountered. It lists the set of valid keys expected at that position, formatted as a backtick-joined list. If exactly one key is valid, the message omits the 'one of' prefix.

Solutions

  1. Use one of the valid keys listed in the error message
  2. Fix typos in the attribute name
  3. Check the diesel version's documentation for supported keys on that derive

Example fix

// before
#[diesel(table_name = users, primary_key(id, extra_key))]
// after
#[diesel(table_name = users, primary_key(id))]
Defensive patterns

Strategy: validation

Validate before calling

const VALID_KEYS: &[&str] = &["sqlite_type", "table_name", "primary_key"];
assert!(VALID_KEYS.contains(&key), "unknown diesel attribute key: {}", key);

Prevention

When it happens

Trigger: Passing any key to a `#[diesel(...)]` attribute that is not in the valid list for that derive/position, e.g. `#[diesel(treat_nane_as_null = true)]` (typo) or a key valid on one derive but not another.

Common situations: Typos in attribute names; copying attributes between derives where the key isn't supported; using attributes from an older/newer diesel version that renamed keys.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of diesel-rs/diesel@6fa6ed01b2 (2026-09-07). Data as JSON: /api/errors/e7be5a8ee701543c. Report an issue: GitHub.

Appendix: source

Thrown at diesel_attribute_parser/src/util.rs:8

use syn::parse::{Parse, ParseStream, Peek, Result};
use syn::token::Eq;
use syn::{Ident, Type, parenthesized};

pub fn unknown_attribute(name: &Ident, valid: &[&str]) -> syn::Error {
    let prefix = if valid.len() == 1 { "" } else { " one of" };

    syn::Error::new(
        name.span(),
        format!(
            "unknown attribute, expected{prefix} `{}`",
            valid.join("`, `")
        ),
    )
}

pub fn parse_eq<T: Parse>(input: ParseStream, help: &str) -> Result<T> {
    if input.is_empty() {
        return Err(syn::Error::new(
            input.span(),
            format!(
                "unexpected end of input, expected `=`\n\
                 help: the correct format looks like `#[diesel({help})]`",
            ),
        ));
    }

View on GitHub (pinned to 6fa6ed01b2)