tauri-apps/tauri · error · syn::Error
unexpected expression for capability
Error message
unexpected expression for capability
What it means
This is a compile-time error from the `tauri::generate_context!` macro. When the `capabilities` attribute is given an array, every element must be a string literal (a path to a capability file). The macro rejects any element that is another kind of expression (number, identifier, function call, etc.) because capability references can only be string paths.
Solutions
- Make every element of the capabilities array a plain string literal, e.g. capabilities = ["capabilities/default"]
- Move dynamic path construction outside the macro and reference files by static string paths
- If you need many capabilities, use a directory entry (a path ending in /*) as a string instead of generating entries programmatically
Example fix
// before
tauri::generate_context!(
"tauri.conf.json",
capabilities = [include_str!("../capabilities/main.json")]
)
// after
tauri::generate_context!(
"tauri.conf.json",
capabilities = ["../capabilities/main.json"]
) Defensive patterns
Strategy: validation
Validate before calling
// Before invoking generate_context!, ensure capabilities entries are string literals. const CAPABILITIES: &[&str] = &["../capabilities/main.json"]; assert!(CAPABILITIES.iter().all(|c| !c.is_empty()), "capabilities must be string paths");
Prevention
- Never place non-literal expressions inside the capabilities array
- Copy-paste a known-good generate_context! invocation when adding capabilities
- Keep capability paths relative and quoted
When it happens
Trigger: Calling `generate_context!` with `capabilities = [<non-string>]`, e.g. `capabilities = [include_str!("...")]`, a variable name, or a numeric literal inside the array.
Common situations: Developers trying to dynamically build the capabilities list (via macros, include_str, or constants) inside the attribute; typos leaving off quotes around a path.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- unexpected list input
- unexpected value for capabilities
- unexpected value for test
- default_runtime only supports `struct`, `enum`, `type`, or…
- ` ` env var not set, do you have a build script with…
AI-assisted analysis of tauri-apps/tauri@460ec35447 (2026-09-18).
Data as JSON: /api/errors/7ad51727437af8b1.
Report an issue: GitHub.
Appendix: source
Thrown at crates/tauri-macros/src/context.rs:80
}
Meta::NameValue(v) => {
let ident = v.path.require_ident()?;
match ident.to_string().as_str() {
"capabilities" => {
if let Expr::Array(array) = v.value {
capabilities.replace(
array
.elems
.into_iter()
.map(|e| {
if let Expr::Lit(ExprLit {
attrs: _,
lit: Lit::Str(s),
}) = e
{
Ok(s.value().into())
} else {
Err(syn::Error::new(
input.span(),
"unexpected expression for capability",
))
}
})
.collect::<Result<Vec<_>, syn::Error>>()?,
);
} else {
return Err(syn::Error::new(
input.span(),
"unexpected value for capabilities",
));
}
}
"assets" => {
assets.replace(v.value);
}
"test" => {View on GitHub (pinned to 460ec35447)