{"record":{"id":"520cec1e7d19835a","repo":"tauri-apps/tauri","slug":"failed-to-serialize-scope","errorCode":null,"errorMessage":"failed to serialize scope","messagePattern":"failed to serialize scope","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tauri/src/ipc/capability_builder.rs","lineNumber":117,"sourceCode":"\n  /// Add a new scoped permission to this capability.\n  pub fn permission_scoped<T: Serialize>(\n    mut self,\n    permission: impl Into<String>,\n    allowed: Vec<T>,\n    denied: Vec<T>,\n  ) -> Self {\n    let permission = permission.into();\n    let identifier = permission\n      .clone()\n      .try_into()\n      .unwrap_or_else(|_| panic!(\"invalid permission identifier '{permission}'\"));\n\n    let allowed_scope = allowed\n      .into_iter()\n      .map(|a| {\n        serde_json::to_value(a)\n          .expect(\"failed to serialize scope\")\n          .into()\n      })\n      .collect();\n    let denied_scope = denied\n      .into_iter()\n      .map(|a| {\n        serde_json::to_value(a)\n          .expect(\"failed to serialize scope\")\n          .into()\n      })\n      .collect();\n    let scope = Scopes {\n      allow: Some(allowed_scope),\n      deny: Some(denied_scope),\n    };\n\n    self\n      .0","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/tauri-apps/tauri/blob/52e4b6e71d8632a7e648f866c442e287ecddee34/crates/tauri/src/ipc/capability_builder.rs#L99-L135","documentation":"While building a runtime capability (CapabilityBuilder), each allowed-scope entry is serialized to a serde_json::Value. The expect fires only when Serialize fails: the value cannot be represented as JSON, e.g. a HashMap with non-string keys, or a custom Serialize impl that returns an error.","triggerScenarios":"Passing an allowed scope value that is a map with non-string keys (HashMap<u32, _>) or a type whose serde serialization can error. Plain strings and string-structs always serialize.","commonSituations":"Custom scope types using numeric-keyed maps; exotic hand-written Serialize impls; almost never triggered with normal string scopes.","solutions":["Use string-keyed maps, plain strings, or structs of strings/vecs for scope entries.","Add a unit test asserting serde_json::to_value(&scope).is_ok() for custom scope types."],"exampleFix":"// before\nlet scope: HashMap<u32, String> = ...; // non-string keys\n\n// after\nlet scope: HashMap<String, String> = ...;","handlingStrategy":"validation","validationCode":"#[test]\nfn allowed_scope_serializes_to_json() {\n    assert!(serde_json::to_value(&my_scope()).is_ok(), \"scope type is not JSON-representable\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use string keys in scope maps.","Avoid custom Serialize impls that can return errors for scope types.","Cover custom scope types with a serialization unit test."],"tags":["tauri","acl","scope","serde","json"],"backgroundTag":"serialization-failed","analyzedSha":"52e4b6e71d8632a7e648f866c442e287ecddee34","analyzedAt":"2026-08-20T13:59:20.734Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}