{"record":{"id":"dcb815b0b19e470a","repo":"dani-garcia/vaultwarden","slug":"error-loading-ciphers","errorCode":null,"errorMessage":"Error loading ciphers","messagePattern":"Error loading ciphers","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"src/db/models/cipher.rs","lineNumber":850,"sourceCode":"                    .filter(ciphers::user_uuid.eq(user_uuid)) // Cipher owner\n                    .or_filter(users_organizations::access_all.eq(true)) // access_all in org\n                    .or_filter(users_collections::user_uuid.eq(user_uuid)) // Access to collection\n                    .or_filter(groups::access_all.eq(true)) // Access via groups\n                    .or_filter(collections_groups::collections_uuid.is_not_null()) // Access via groups\n                    .into_boxed();\n\n                if !visible_only {\n                    query = query.or_filter(\n                        users_organizations::atype.le(MembershipType::Admin as i32), // Org admin/owner\n                    );\n                }\n\n                // Only filter for one specific cipher\n                if !cipher_uuids.is_empty() {\n                    query = query.filter(ciphers::uuid.eq_any(cipher_uuids));\n                }\n\n                query.select(ciphers::all_columns).distinct().load::<Self>(conn).expect(\"Error loading ciphers\")\n            })\n            .await\n        } else {\n            conn.run(move |conn| {\n                let mut query = ciphers::table\n                    .left_join(ciphers_collections::table.on(ciphers::uuid.eq(ciphers_collections::cipher_uuid)))\n                    .left_join(\n                        users_organizations::table.on(ciphers::organization_uuid\n                            .eq(users_organizations::org_uuid.nullable())\n                            .and(users_organizations::user_uuid.eq(user_uuid))\n                            .and(users_organizations::status.eq(MembershipStatus::Confirmed as i32))),\n                    )\n                    .left_join(\n                        users_collections::table.on(ciphers_collections::collection_uuid\n                            .eq(users_collections::collection_uuid)\n                            // Ensure that users_collections::user_uuid is NULL for unconfirmed users.\n                            .and(users_organizations::user_uuid.eq(users_collections::user_uuid))),\n                    )","sourceCodeStart":832,"sourceCodeEnd":868,"githubUrl":"https://github.com/dani-garcia/vaultwarden/blob/cc67d644f62605cb46f4d16c4a2eed1a861cc8bb/src/db/models/cipher.rs#L832-L868","documentation":"find_by_user loads the user's visible ciphers via Diesel .load::<Self> and unwraps with .expect(\"Error loading ciphers\"). Any database failure during this query panics with this message: connection loss, schema mismatch, or deserialization errors.","triggerScenarios":"DB connection dropped mid-query, migrations not applied so the ciphers table/columns are missing, or a row whose column types/NULLs don't match the Cipher model fields.","commonSituations":"Upgrading Vaultwarden without running migrations (old schema); Postgres/MySQL restarted or pooled connections expired; manually edited schema diverging from diesel models.","solutions":["Run pending migrations (automatic on startup; check DB schema version table)","Verify DB connectivity and that the ciphers table exists with expected columns","Check server logs for the underlying Diesel error printed before the panic","Restore schema consistency from backup or re-run migrations after schema drift"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// before calling find_by_user, confirm schema is current:\n// run `vaultwarden` once and verify 'Migrations completed' in logs,\n// or check the __diesel_schema_migrations table has the latest version.","typeGuard":null,"tryCatchPattern":"match ciphers::find_by_user(&user_uuid, &conn).await {\n  Ok(list) => list,\n  Err(e) => { error!(\"Cipher load failed: {e}\"); return api_err(500); }\n}","preventionTips":["Always let Vaultwarden run its migrations on startup","Monitor DB connectivity and pool health","Avoid manual schema edits; track diesel schema.rs in upgrades","Verify schema after restore-from-backup operations"],"tags":["database","diesel","panic"],"backgroundTag":"database-query-failed","analyzedSha":"cc67d644f62605cb46f4d16c4a2eed1a861cc8bb","analyzedAt":"2026-09-19T08:28:46.370Z","contentChangedAt":"2026-09-19T08:28:46.370Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}