{"record":{"id":"7ad51727437af8b1","repo":"tauri-apps/tauri","slug":"unexpected-expression-for-capability","errorCode":null,"errorMessage":"unexpected expression for capability","messagePattern":"unexpected expression for capability","errorType":"validation","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"crates/tauri-macros/src/context.rs","lineNumber":80,"sourceCode":"        }\n        Meta::NameValue(v) => {\n          let ident = v.path.require_ident()?;\n          match ident.to_string().as_str() {\n            \"capabilities\" => {\n              if let Expr::Array(array) = v.value {\n                capabilities.replace(\n                  array\n                    .elems\n                    .into_iter()\n                    .map(|e| {\n                      if let Expr::Lit(ExprLit {\n                        attrs: _,\n                        lit: Lit::Str(s),\n                      }) = e\n                      {\n                        Ok(s.value().into())\n                      } else {\n                        Err(syn::Error::new(\n                          input.span(),\n                          \"unexpected expression for capability\",\n                        ))\n                      }\n                    })\n                    .collect::<Result<Vec<_>, syn::Error>>()?,\n                );\n              } else {\n                return Err(syn::Error::new(\n                  input.span(),\n                  \"unexpected value for capabilities\",\n                ));\n              }\n            }\n            \"assets\" => {\n              assets.replace(v.value);\n            }\n            \"test\" => {","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/tauri-apps/tauri/blob/52e4b6e71d8632a7e648f866c442e287ecddee34/crates/tauri-macros/src/context.rs#L62-L98","documentation":"#[tauri::generate_context] accepts a capabilities = [...] override selecting which capability identifiers are embedded. Each array element must be a string literal, because the macro resolves the names against the project's capabilities at compile time. A const path, macro call, number, or any other expression element fails with 'unexpected expression for capability'.","triggerScenarios":"#[tauri::generate_context(capabilities = [\"core:default\", MY_CAPS])] where MY_CAPS is a const, or elements like concat!(\"core:\", name) or 42.","commonSituations":"Trying to DRY capability lists through consts or macros; copying runtime-string patterns into a compile-time attribute; capability names produced by build scripts.","solutions":["Inline every capability as a string literal in the array","If lists must stay in sync, have build.rs write a generated .rs file containing the whole #[tauri::generate_context(...)] invocation with literals and include it","Prefer the default behavior (all capabilities under src-tauri/capabilities are picked up) and drop the override"],"exampleFix":"// before\nconst MAIN_CAPS: &str = \"core:default\";\n#[tauri::generate_context(capabilities = [\"core:webview\", MAIN_CAPS])]\n// after\n#[tauri::generate_context(capabilities = [\"core:webview\", \"core:default\"])]","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Write capability array elements as string literals only","Generate the attribute invocation from build.rs if the list must stay in sync","Prefer the default (all capabilities in src-tauri/capabilities) over the override"],"tags":["macros","generate-context","capabilities","compile-time","string-literal"],"backgroundTag":"macro-attribute-syntax-error","analyzedSha":"52e4b6e71d8632a7e648f866c442e287ecddee34","analyzedAt":"2026-08-20T13:59:20.734Z","contentChangedAt":"2026-08-20T13:59:20.734Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}