{"record":{"id":"52c8d9a44904907f","repo":"leptos-rs/leptos","slug":"keyword-argument-repeated-encoding","errorCode":null,"errorMessage":"keyword argument repeated: `encoding`","messagePattern":"keyword argument repeated: `encoding`","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server_fn_macro/src/lib.rs","lineNumber":1097,"sourceCode":"                    if key == \"name\" {\n                        if struct_name.is_some() {\n                            return Err(syn::Error::new(\n                                key.span(),\n                                \"keyword argument repeated: `name`\",\n                            ));\n                        }\n                        struct_name = Some(stream.parse()?);\n                    } else if key == \"prefix\" {\n                        if prefix.is_some() {\n                            return Err(syn::Error::new(\n                                key.span(),\n                                \"keyword argument repeated: `prefix`\",\n                            ));\n                        }\n                        prefix = Some(stream.parse()?);\n                    } else if key == \"encoding\" {\n                        if encoding.is_some() {\n                            return Err(syn::Error::new(\n                                key.span(),\n                                \"keyword argument repeated: `encoding`\",\n                            ));\n                        }\n                        encoding = Some(stream.parse()?);\n                    } else if key == \"endpoint\" {\n                        if fn_path.is_some() {\n                            return Err(syn::Error::new(\n                                key.span(),\n                                \"keyword argument repeated: `endpoint`\",\n                            ));\n                        }\n                        fn_path = Some(stream.parse()?);\n                    } else if key == \"input\" {\n                        if encoding.is_some() {\n                            return Err(syn::Error::new(\n                                key.span(),\n                                \"`encoding` and `input` should not both be \\","sourceCodeStart":1079,"sourceCodeEnd":1115,"githubUrl":"https://github.com/leptos-rs/leptos/blob/32d20f6c9d517451d77beb68d88c7716823dac41/server_fn_macro/src/lib.rs#L1079-L1115","documentation":"This error is thrown by the #[server] macro's attribute parser in server_fn_macro when the `encoding` keyword argument appears more than once in the attribute. Since macro attributes are parsed as a token stream at compile time, duplicates cannot be represented, so the parser eagerly rejects them with a compile error pointing at the repeated key.","triggerScenarios":"Writing #[server(...)] with two `encoding = \"...\"` entries, e.g. after copy-pasting or merging attribute lines such as #[server(encoding = \"Url\", encoding = \"Json\")] or combining two macro invocations via macro_rules that both inject encoding.","commonSituations":"Copy-pasting attribute args from another function, refactoring code where encoding was added twice, or a macro_rules! wrapper that appends its own encoding alongside a user-supplied one.","solutions":["Remove the duplicate `encoding = ...` entry, keeping only one.","If you need a different input/output encoding, replace the single `encoding` with `input` and/or `output` arguments instead (they are mutually exclusive with `encoding`).","If the duplicate comes from a macro_rules! wrapper, make the wrapper not emit encoding when the caller already supplies it."],"exampleFix":"// before\n#[server(encoding = \"Url\", encoding = \"Json\")]\nasync fn save(data: String) -> Result<(), ServerFnError> { todo!() }\n\n// after\n#[server(encoding = \"Url\")]\nasync fn save(data: String) -> Result<(), ServerFnError> { todo!() }","handlingStrategy":"validation","validationCode":"// Compile-time guard: ensure each #[server] attribute declares `encoding` at most once.\n// Grep-based pre-commit check:\n// grep -rnE '#\\[server\\(([^)\\n]*encoding[^\n)]*){2,}' src/ && exit 1 || exit 0","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Specify each keyword argument at most once in #[server].","Prefer `input`/`output` over `encoding` when custom types are needed — encoding is mutually exclusive with both.","Run `cargo check` locally before committing; macro attribute errors surface only at compile time.","Keep attribute args on distinct, commented lines in macro_rules! wrappers and make injection conditional."],"tags":["rust","proc-macro","compile-time","server-fn"],"backgroundTag":"duplicate-macro-attribute-argument","analyzedSha":"32d20f6c9d517451d77beb68d88c7716823dac41","analyzedAt":"2026-09-01T18:55:42.580Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T01:17:15.007Z"}