tauri-apps/tauri · error · syn::Error
only named, wildcard, struct, and tuple struct arguments…
Error message
only named, wildcard, struct, and tuple struct arguments allowed
What it means
Command parameters must map to a named JS-observable key, so parse_arg supports only identifier patterns, wildcards (_), struct patterns, and tuple-struct patterns. Any other pattern (literals, slices, tuples, refs as patterns, etc.) fails with this compile-time error.
Solutions
- Replace the unsupported pattern with a named struct or single named argument (define a struct parameter and destructure inside the body)
- Use plain named arguments for each value instead of tuple/array destructuring
- If only part of the value is needed, bind the whole argument to a name and destructure in the function body
Example fix
// before
#[tauri::command]
fn cmd((a, b): (i32, i32)) -> i32 { a + b }
// after
#[tauri::command]
fn cmd(pair: PairArg) -> i32 { pair.a + pair.b }
// with #[serde(rename_all="camelCase")] struct PairArg { a: i32, b: i32 } Defensive patterns
Strategy: type-guard
Prevention
- Use only named arguments in command signatures; destructure inside the body
- Model complex payloads as serde structs rather than tuple/array patterns
- Avoid macros/formatters that rewrite command parameter patterns
When it happens
Trigger: Destructuring unsupported shapes in a command signature, e.g. fn cmd((a, b): (i32, i32)) (plain tuple), fn cmd([x, y]: [i32; 2]), fn cmd(1 = ...) style literal patterns, or reference patterns.
Common situations: Trying to accept destructured arrays/tuples from the frontend; auto-formatting or macro-generated code introducing non-ident patterns; porting a Rust API with tuple arguments into a command.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- expected "camelCase" or "snake_case"
- expected string literal for rename
- parsed syn::Path has no segment
- path has at least one segment
- unable to use self as a command function parameter
AI-assisted analysis of tauri-apps/tauri@460ec35447 (2026-09-18).
Data as JSON: /api/errors/d5329e59d03e2044.
Report an issue: GitHub.
Appendix: source
Thrown at crates/tauri-macros/src/command/wrapper.rs:484
// we have no use for self arguments
let mut arg = match arg {
FnArg::Typed(arg) => arg.pat.as_ref().clone(),
FnArg::Receiver(arg) => {
return Err(syn::Error::new(
arg.span(),
"unable to use self as a command function parameter",
));
}
};
// we only support patterns that allow us to extract some sort of keyed identifier
let mut key = match &mut arg {
Pat::Ident(arg) => arg.ident.unraw().to_string(),
Pat::Wild(_) => "".into(), // we always convert to camelCase, so "_" will end up empty anyways
Pat::Struct(s) => super::path_to_command(&mut s.path).ident.to_string(),
Pat::TupleStruct(s) => super::path_to_command(&mut s.path).ident.to_string(),
err => {
return Err(syn::Error::new(
err.span(),
"only named, wildcard, struct, and tuple struct arguments allowed",
));
}
};
// also catch self arguments that use FnArg::Typed syntax
if key == "self" {
return Err(syn::Error::new(
key.span(),
"unable to use self as a command function parameter",
));
}
match attributes.argument_case {
ArgumentCase::Camel => {
key = key.to_lower_camel_case();
}View on GitHub (pinned to 460ec35447)