leptos-rs/leptos · error
Encoding not found.
Error message
Encoding not found.
What it means
The `encoding` option (or third positional string) is validated against the set of built-in encodings known to the macro (e.g. Url, GetJson, PostJson, PostCbor, etc., matched case-insensitively). Any other value fails this check with 'Encoding not found.' at the encoding literal's span.
Source
Thrown at server_fn_macro/src/lib.rs:1230
));
}
}
} else if lookahead.peek(LitStr) {
if use_key_and_value {
return Err(syn::Error::new(
stream.span(),
"If you use keyword arguments (e.g., `name` = \
Something), then you can no longer use arguments \
without a keyword.",
));
}
match arg_pos {
1 => return Err(lookahead.error()),
2 => prefix = Some(stream.parse()?),
3 => encoding = Some(stream.parse()?),
4 => fn_path = Some(stream.parse()?),
_ => {
return Err(syn::Error::new(
stream.span(),
"unexpected extra argument",
))
}
}
} else {
return Err(lookahead.error());
}
if !stream.is_empty() {
stream.parse::<Token![,]>()?;
}
}
// parse legacy encoding into input/output
let mut builtin_encoding = false;
if let Some(encoding) = encoding {
match encoding.value().to_lowercase().as_str() {View on GitHub (pinned to 32d20f6c9d)
Solutions
- Use one of the supported builtin encoding strings (Url, GetText, PostText, GetBinary, PostBinary, GetJson, PostJson, PostCbor, GetCBOR-style idents are matched case-insensitively).
- For non-builtin serialization, omit `encoding` and specify `input`/`output` (and optionally `custom`) types instead.
- Check spelling/case and any recent renames of encodings in the crate docs.
Example fix
// before #[server(encoding = "msgpack")] // after #[server(encoding = "PostCbor")] // or for custom: // #[server(input = MyInput, output = MyOutput)]
Defensive patterns
Strategy: validation
Validate before calling
const BUILTIN_ENCODINGS: &[&str] = &["url","gettext","posttext","getbinary","postbinary","getjson","postjson","postcbor"];
let enc = "msgpack";
assert!(BUILTIN_ENCODINGS.contains(&enc.to_lowercase().as_str()), "unsupported encoding: {enc}"); Prevention
- Copy encoding names from the crate docs, not memory
- Use input/output/custom for anything non-builtin
- Add a CI grep test listing allowed encodings used in the repo
When it happens
Trigger: #[server(encoding = "json")] (lowercase name not in the builtin list); misspelling like 'PostJSon' variants that don't match; passing an encoding name from a different framework; using a custom encoding that requires input/output/custom instead.
Common situations: Copying encodings from other libraries (e.g. 'msgpack' when only Cbor is builtin); typos in the encoding string; switching to custom serialization without switching options.
Related errors
- keyword argument repeated: `encoding`
- keyword argument repeated: `endpoint`
- `encoding` and `input` should not both be specified
- keyword argument repeated: `input`
- `encoding` and `output` should not both be specified
AI-assisted analysis of leptos-rs/leptos@32d20f6c9d (2026-09-01).
Data as JSON: /api/errors/0164ff05c9907f9c.
Report an issue: GitHub.