{"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/460ec35447493200d64290dd7f015d5a91d0fd58/crates/tauri/src/ipc/capability_builder.rs#L99-L135","documentation":"Panic in CapabilityBuilder::permission_scoped when serde_json::to_value fails to serialize a scope entry passed to the scoped-permission API. Scope entries must be JSON-serializable values (strings or objects); a non-serializable input makes the expect fire and the capability build aborts.","triggerScenarios":"Calling permission_scoped (or related scoped APIs) with allowed/denied scope entries whose serialized form cannot be represented as JSON — e.g. a type with a non-string key map or a serializer that errors (NaN, custom Serialize impl returning Err).","commonSituations":"Passing scope objects built from non-JSON-compatible Rust types (e.g. HashMap with non-string keys), typos producing values serde cannot serialize, or using a custom type whose Serialize implementation fails.","solutions":["Ensure scope entries are plain JSON values: strings, or objects with string keys","Check the permission's documented scope schema (e.g. fs:scope expects {\"path\": ...} or \"**\")","Test serialization manually with serde_json::to_value(&entry) before calling permission_scoped","Fix or replace custom Serialize impls that can return errors"],"exampleFix":"// before\nlet mut scope = HashMap::new();\nscope.insert(1, \"**\"); // non-string key -> serialization fails\nbuilder.permission_scoped(\"fs:allow-read\", vec![scope], vec![]);\n// after\nbuilder.permission_scoped(\"fs:allow-read\", vec![serde_json::json!({\"path\": \"**\"})], vec![]);","handlingStrategy":"validation","validationCode":"for entry in &allowed {\n    serde_json::to_value(entry).expect(\"scope entry not JSON-serializable\");\n}","typeGuard":null,"tryCatchPattern":"let value = serde_json::to_value(entry)\n    .map_err(|e| format!(\"failed to serialize scope: {e}\"))?;","preventionTips":["Build scopes with serde_json::json! literals or string values only","Avoid maps with non-string keys in scope objects","Unit-test custom Serialize impls for infallibility"],"tags":["ipc","capability","serde","json","scope"],"backgroundTag":"json-serialization-failed","analyzedSha":"460ec35447493200d64290dd7f015d5a91d0fd58","analyzedAt":"2026-09-18T23:55:51.277Z","contentChangedAt":"2026-09-18T23:55:51.277Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}