tauri-apps/tauri · error · syn::Error

unexpected value for capabilities

Error message

unexpected value for capabilities

What it means

The capabilities key of #[tauri::generate_context] must be an array expression (Expr::Array) whose elements are string literals. If the value is any other expression kind — a bare string, a const, a function call — the macro rejects the whole value with 'unexpected value for capabilities'.

Source

Thrown at crates/tauri-macros/src/context.rs:89

                    .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" => {
              if let Expr::Lit(ExprLit {
                lit: Lit::Bool(LitBool { value, .. }),
                ..
              }) = v.value
              {
                test = value;
              } else {
                return Err(syn::Error::new(input.span(), "unexpected value for test"));
              }

View on GitHub (pinned to 52e4b6e71d)

Solutions

  1. Wrap the value in an array of string literals: capabilities = ["core:default"]
  2. Remove the key entirely to embed all capabilities found in src-tauri/capabilities
  3. Keep in mind the attribute is evaluated at compile time: no runtime values are possible

Example fix

// before
#[tauri::generate_context(capabilities = "core:default")]
// after
#[tauri::generate_context(capabilities = ["core:default"])]
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: #[tauri::generate_context(capabilities = "core:default")] (string instead of array), or capabilities = CAPABILITIES where CAPABILITIES is a const Vec/&[&str].

Common situations: Shorthand thinking where one capability is written without brackets; refactoring shared capability lists into consts; JSON-style single values copied from tauri.conf.json.

Related errors


AI-assisted analysis of tauri-apps/tauri@52e4b6e71d (2026-08-20). Data as JSON: /api/errors/c290daad9627182d. Report an issue: GitHub.