leptos-rs/leptos · error
keyword argument repeated: `encoding`
Error message
keyword argument repeated: `encoding`
What it means
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.
Source
Thrown at server_fn_macro/src/lib.rs:1097
if key == "name" {
if struct_name.is_some() {
return Err(syn::Error::new(
key.span(),
"keyword argument repeated: `name`",
));
}
struct_name = Some(stream.parse()?);
} else if key == "prefix" {
if prefix.is_some() {
return Err(syn::Error::new(
key.span(),
"keyword argument repeated: `prefix`",
));
}
prefix = Some(stream.parse()?);
} else if key == "encoding" {
if encoding.is_some() {
return Err(syn::Error::new(
key.span(),
"keyword argument repeated: `encoding`",
));
}
encoding = Some(stream.parse()?);
} else if key == "endpoint" {
if fn_path.is_some() {
return Err(syn::Error::new(
key.span(),
"keyword argument repeated: `endpoint`",
));
}
fn_path = Some(stream.parse()?);
} else if key == "input" {
if encoding.is_some() {
return Err(syn::Error::new(
key.span(),
"`encoding` and `input` should not both be \View on GitHub (pinned to 32d20f6c9d)
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.
Example fix
// before
#[server(encoding = "Url", encoding = "Json")]
async fn save(data: String) -> Result<(), ServerFnError> { todo!() }
// after
#[server(encoding = "Url")]
async fn save(data: String) -> Result<(), ServerFnError> { todo!() } Defensive patterns
Strategy: validation
Validate before calling
// Compile-time guard: ensure each #[server] attribute declares `encoding` at most once.
// Grep-based pre-commit check:
// grep -rnE '#\[server\(([^)\n]*encoding[^
)]*){2,}' src/ && exit 1 || exit 0 Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- keyword argument repeated: `endpoint`
- `encoding` and `input` should not both be specified
- keyword argument repeated: `input`
- `encoding` and `output` should not both be specified
- keyword argument repeated: `output`
AI-assisted analysis of leptos-rs/leptos@32d20f6c9d (2026-09-01).
Data as JSON: /api/errors/52c8d9a44904907f.
Report an issue: GitHub.