{"record":{"id":"b138188852ec36b6","repo":"dani-garcia/vaultwarden","slug":"error-loading-collections","errorCode":null,"errorMessage":"Error loading collections","messagePattern":"Error loading collections","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"src/db/models/collection.rs","lineNumber":271,"sourceCode":"                            .eq(user_uuid)\n                            .or(\n                                // Directly accessed collection\n                                users_organizations::access_all.eq(true), // access_all in Organization\n                            )\n                            .or(\n                                groups::access_all.eq(true), // access_all in groups\n                            )\n                            .or(\n                                // access via groups\n                                groups_users::users_organizations_uuid\n                                    .eq(users_organizations::uuid)\n                                    .and(collections_groups::collections_uuid.is_not_null()),\n                            ),\n                    )\n                    .select(collections::all_columns)\n                    .distinct()\n                    .load::<Self>(conn)\n                    .expect(\"Error loading collections\")\n            })\n            .await\n        } else {\n            conn.run(move |conn| {\n                collections::table\n                    .left_join(\n                        users_collections::table.on(users_collections::collection_uuid\n                            .eq(collections::uuid)\n                            .and(users_collections::user_uuid.eq(user_uuid.clone()))),\n                    )\n                    .left_join(\n                        users_organizations::table.on(collections::org_uuid\n                            .eq(users_organizations::org_uuid)\n                            .and(users_organizations::user_uuid.eq(user_uuid.clone()))),\n                    )\n                    .filter(users_organizations::status.eq(MembershipStatus::Confirmed as i32))\n                    .filter(users_collections::user_uuid.eq(user_uuid).or(\n                        // Directly accessed collection","sourceCodeStart":253,"sourceCodeEnd":289,"githubUrl":"https://github.com/dani-garcia/vaultwarden/blob/cc67d644f62605cb46f4d16c4a2eed1a861cc8bb/src/db/models/collection.rs#L253-L289","documentation":"Panic from `expect` when the first branch of `Collection::find_by_user_uuid` (used when org groups are enabled) fails to load the user's collections. This complex query joins users_organizations, collections, and collections_groups; any SQL or deserialization failure panics. Empty results are fine; only execution errors trigger this.","triggerScenarios":"Calling `Collection::find_by_user_uuid` with `org_groups_enabled` true when the `groups`/`collections_groups` tables are missing (migrations not run after enabling groups), DB connectivity fails, or join column types drift from the models.","commonSituations":"Enabling ORG_GROUPS_ENABLED=true on a database created by an older version without group tables; failed/partial migration; schema drift from manual DDL; SQLite file corruption.","solutions":["Run database migrations to create/upgrade groups and collections_groups tables","Log the underlying diesel error before the expect to see the true cause","Verify DB connectivity and credentials","If groups are not needed, disable org groups in config so the simpler query branch runs","Restore the schema to match the compiled models"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// If enabling org groups, first verify group tables exist (SQLite)\nlet ok = conn.run(|c| diesel::select(diesel::dsl::sql::<diesel::sql_types::Bool>(\n    \"SELECT EXISTS(SELECT 1 FROM sqlite_master WHERE name='collections_groups')\"\n)).load::<bool>(c)).await.unwrap_or(vec![false]).into_iter().next().unwrap_or(false);\nif !ok { panic!(\"ORG_GROUPS_ENABLED but group tables missing; run migrations\"); }","typeGuard":null,"tryCatchPattern":"let r = std::panic::catch_unwind(std::panic::AssertUnwindSafe(async {\n    Collection::find_by_user_uuid(&user_uuid, &conn).await\n}));\nif r.is_err() { log::error!(\"collection lookup for user panicked; check group tables/migrations\"); }","preventionTips":["Enable ORG_GROUPS_ENABLED only after migrations have created group tables","Run migrations before applying config changes","Log the underlying diesel error when diagnosing","Verify joins cover users_organizations, collections_groups, groups tables","Test with a fresh DB provisioned by migrations"],"tags":["rust","diesel","database","panic","groups"],"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"}