{"record":{"id":"40e3d08d09198dda","repo":"BoundaryML/baml","slug":"variant-must-declare-exactly-one-axis","errorCode":null,"errorMessage":"variant `{}` must declare exactly one `#[axis(..)]`","messagePattern":"variant `(.+?)` must declare exactly one `#\\[axis\\(\\.\\.\\)\\]`","errorType":"validation","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"baml_language/crates/baml_type_macros/src/parse.rs","lineNumber":412,"sourceCode":"    let mut attrs = Vec::new();\n    for attr in variant.attrs {\n        if attr.path().is_ident(\"axis\") {\n            if axis_ident.is_some() {\n                return Err(syn::Error::new(\n                    span,\n                    format!(\n                        \"variant `{}` has more than one `#[axis(..)]`\",\n                        variant.ident\n                    ),\n                ));\n            }\n            axis_ident = Some(attr.parse_args_with(Ident::parse_any)?);\n        } else {\n            attrs.push(attr);\n        }\n    }\n    let axis_ident = axis_ident.ok_or_else(|| {\n        syn::Error::new(\n            span,\n            format!(\n                \"variant `{}` must declare exactly one `#[axis(..)]`\",\n                variant.ident\n            ),\n        )\n    })?;\n    let axis = axis_index(&axis_ident)?;\n    let discriminant = match variant.discriminant.as_ref().map(|(_, expr)| expr) {\n        Some(syn::Expr::Lit(syn::ExprLit {\n            lit: syn::Lit::Int(value),\n            ..\n        })) => value.base10_parse::<u8>()?,\n        Some(expr) => {\n            return Err(syn::Error::new_spanned(\n                expr,\n                \"type-family variants require an explicit u8 integer discriminant\",\n            ));","sourceCodeStart":394,"sourceCodeEnd":430,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/baml_type_macros/src/parse.rs#L394-L430","documentation":"Every variant of a derive-defined type-family enum must declare exactly one `#[axis(..)]` attribute. `resolve_variant` collects axis idents and, if none was found, raises this error. The axis is required for the macro to classify the variant.","triggerScenarios":"Declaring a variant with no `#[axis(..)]` attribute; `axis_ident` is `None` after the attribute loop, triggering the `ok_or_else` error.","commonSituations":"Adding a new variant to an existing type-family enum and forgetting the attribute; removing an attribute during refactoring.","solutions":["Add a `#[axis(SomeAxisIdent)]` attribute to the variant.","Check sibling variants for the correct axis naming pattern and copy it.","If the variant belongs to no axis, move it to a separate enum outside the derive."],"exampleFix":"// before\nVariant { field: u32 },\n// after\n#[axis(Type)]\nVariant { field: u32 },","handlingStrategy":"validation","validationCode":"// before deriving, confirm each variant has an axis\n// variant list must satisfy: every variant carries exactly one #[axis(..)]","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Copy an existing variant as a template so the attribute is never dropped","Add a checklist step when introducing new type-family variants","Keep a doc comment on the enum stating the axis requirement"],"tags":["proc-macro","compile-time","attributes","rust"],"backgroundTag":"missing-required-argument","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}