From d37a0a4219f0bfe6f83070bb006e1d20de6ff326 Mon Sep 17 00:00:00 2001 From: easonysliu Date: Thu, 9 Apr 2026 14:30:36 +0800 Subject: [PATCH] fix: return error instead of panicking on invalid cipher type in to_json `Cipher::to_json()` returns `Result` but its match arm for unknown `atype` values called `panic!("Wrong type")` instead of propagating an error. This means if a cipher with an invalid/unknown type ends up in the database (via direct DB edits, data migration issues, or future type additions in the upstream Bitwarden protocol), the entire server process would crash on the next sync request. Replace the `panic!` with `err!()` so callers receive a proper `Err` and can handle or log it gracefully without taking down the server. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/db/models/cipher.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/db/models/cipher.rs b/src/db/models/cipher.rs index b28a25cd..ac2d9f4a 100644 --- a/src/db/models/cipher.rs +++ b/src/db/models/cipher.rs @@ -398,7 +398,7 @@ impl Cipher { 3 => "card", 4 => "identity", 5 => "sshKey", - _ => panic!("Wrong type"), + _ => err!(format!("Cipher {} has an invalid type {}", self.uuid, self.atype)), }; json_object[key] = type_data_json;