{"record":{"id":"a198881812723eae","repo":"tauri-apps/tauri","slug":"invalid-capability","errorCode":null,"errorMessage":"invalid capability","messagePattern":"invalid capability","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tauri/src/ipc/capability_builder.rs","lineNumber":22,"sourceCode":"\nuse serde::Serialize;\nuse tauri_utils::{\n  acl::{\n    capability::{Capability, CapabilityFile, PermissionEntry},\n    Scopes,\n  },\n  platform::Target,\n};\n\n/// A capability that can be added at runtime.\npub trait RuntimeCapability {\n  /// Creates the capability file.\n  fn build(self) -> CapabilityFile;\n}\n\nimpl<T: AsRef<str>> RuntimeCapability for T {\n  fn build(self) -> CapabilityFile {\n    self.as_ref().parse().expect(\"invalid capability\")\n  }\n}\n\n/// A builder for a [`Capability`].\npub struct CapabilityBuilder(Capability);\n\nimpl CapabilityBuilder {\n  /// Creates a new capability builder with a unique identifier.\n  pub fn new(identifier: impl Into<String>) -> Self {\n    Self(Capability {\n      identifier: identifier.into(),\n      description: \"\".into(),\n      remote: None,\n      local: true,\n      windows: Vec::new(),\n      webviews: Vec::new(),\n      permissions: Vec::new(),\n      platforms: None,","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/tauri-apps/tauri/blob/52e4b6e71d8632a7e648f866c442e287ecddee34/crates/tauri/src/ipc/capability_builder.rs#L4-L40","documentation":"RuntimeCapability is implemented for any &str/String: build() parses the string into a CapabilityFile, trying JSON first, then TOML. The expect panics when the string is neither valid JSON nor valid TOML, or does not match the capability schema (missing identifier, malformed permissions/webviews/remote fields). It backs Manager::add_capability, so app.add_capability(\"...\") with a bad string panics.","triggerScenarios":"Passing a malformed or wrong-format capability string to app.add_capability: YAML capability content (only JSON/TOML are parsed), JSON missing required fields such as identifier, or a file path instead of the file contents.","commonSituations":"Copying a capabilities/*.yaml file's content into runtime code; hand-written JSON typos; passing a path where contents were expected.","solutions":["Pre-parse to see the real error: let r: Result<CapabilityFile, _> = s.parse(); inspect the Err before calling add_capability.","Use JSON or TOML only, with required fields (identifier, permissions) present.","If sourcing from a file, read it to a string first (include_str!) and validate contents, not the path."],"exampleFix":"// before\napp.add_capability(\"capabilities/beta/cap.json\"); // path, not contents\n\n// after\nlet raw = include_str!(\"../capabilities/beta/cap.json\");\nlet parsed: tauri_utils::acl::capability::CapabilityFile = raw.parse().expect(\"capability file must be valid JSON/TOML\");\napp.add_capability(raw);","handlingStrategy":"validation","validationCode":"// validate before handing the string to add_capability\nlet cap: Result<tauri_utils::acl::capability::CapabilityFile, _> = raw.parse();\nassert!(cap.is_ok(), \"capability string is not valid JSON/TOML: {:?}\", cap.err());\napp.add_capability(raw);","typeGuard":"fn is_valid_capability_str(s: &str) -> bool {\n    s.parse::<tauri_utils::acl::capability::CapabilityFile>().is_ok()\n}","tryCatchPattern":null,"preventionTips":["Use include_str! on capability files, never a bare path string.","Validate capability strings in unit tests with .parse() before shipping.","Remember only JSON and TOML are accepted; convert YAML beforehand."],"tags":["tauri","acl","capability","json","toml","runtime"],"backgroundTag":"schema-validation-failed","analyzedSha":"52e4b6e71d8632a7e648f866c442e287ecddee34","analyzedAt":"2026-08-20T13:59:20.734Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}