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

  1. Make every element of the capabilities array a plain string literal, e.g. capabilities = ["capabilities/default"]
  2. Move dynamic path construction outside the macro and reference files by static string paths
  3. 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

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


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)