{"record":{"id":"85b13a6db4772dcb","repo":"dani-garcia/vaultwarden","slug":"error-loading-user-collection-groups","errorCode":null,"errorMessage":"Error loading user collection groups","messagePattern":"Error loading user collection groups","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/db/models/group.rs","lineNumber":389,"sourceCode":"            collections_groups::table\n                .inner_join(groups_users::table.on(groups_users::groups_uuid.eq(collections_groups::groups_uuid)))\n                .inner_join(\n                    users_organizations::table.on(users_organizations::uuid.eq(groups_users::users_organizations_uuid)),\n                )\n                .inner_join(\n                    groups::table.on(groups::uuid\n                        .eq(collections_groups::groups_uuid)\n                        .and(groups::organizations_uuid.eq(users_organizations::org_uuid))),\n                )\n                .inner_join(\n                    collections::table.on(collections::uuid\n                        .eq(collections_groups::collections_uuid)\n                        .and(collections::org_uuid.eq(groups::organizations_uuid))),\n                )\n                .filter(users_organizations::user_uuid.eq(user_uuid))\n                .select(collections_groups::all_columns)\n                .load::<Self>(conn)\n                .expect(\"Error loading user collection groups\")\n        })\n        .await\n    }\n\n    pub async fn find_by_collection(collection_uuid: &CollectionId, conn: &DbConn) -> Vec<Self> {\n        conn.run(move |conn| {\n            collections_groups::table\n                .filter(collections_groups::collections_uuid.eq(collection_uuid))\n                .inner_join(collections::table.on(collections::uuid.eq(collections_groups::collections_uuid)))\n                .inner_join(\n                    groups::table.on(groups::uuid\n                        .eq(collections_groups::groups_uuid)\n                        .and(groups::organizations_uuid.eq(collections::org_uuid))),\n                )\n                .select(collections_groups::all_columns)\n                .load::<Self>(conn)\n                .expect(\"Error loading collection groups\")\n        })","sourceCodeStart":371,"sourceCodeEnd":407,"githubUrl":"https://github.com/dani-garcia/vaultwarden/blob/cc67d644f62605cb46f4d16c4a2eed1a861cc8bb/src/db/models/group.rs#L371-L407","documentation":"Panic from `.expect()` on the Diesel query in `CollectionGroup::find_by_user`, joining users_organizations, groups and collections_groups to list a user's collection-group memberships. A database-level failure aborts the call. Like its sibling queries, a valid-but-unmapped user simply returns an empty Vec; only real DB errors reach this expect.","triggerScenarios":"Calling `CollectionGroup::find_by_user` when the DB is unreachable, joined tables lack expected columns (e.g. collections_groups missing), or the connection drops mid-query.","commonSituations":"Upgrade without migrations on an old schema; database outage or restart during sync; SQLite file lock/permission problems; connection-pool exhaustion under load.","solutions":["Run all pending migrations so users_organizations, groups and collections_groups schemas match the code","Verify DB connectivity and credentials in DATABASE_URL","Check server logs for the underlying Diesel error behind the panic","Resolve SQLite lock/permission issues or recycle the connection pool if connection-related"],"exampleFix":"// before\n.load::<Self>(conn).expect(\"Error loading user collection groups\")\n// after\n.load::<Self>(conn).unwrap_or_else(|e| { error!(\"load user collection groups failed: {e}\"); Vec::new() })","handlingStrategy":"try-catch","validationCode":"// ensure user exists in users_organizations before membership lookups\nlet is_member = UsersOrganizations::find_by_user_and_org(user, org, conn).await.is_some();","typeGuard":null,"tryCatchPattern":"// health-gate the multi-join query\nif !db_ok().await { return Vec::new(); }\nCollectionGroup::find_by_user(user_uuid, conn).await","preventionTips":["Run startup migrations every deployment","Keep an eye on connection-pool metrics under sync load","Use WAL/journal settings appropriate for your SQLite usage","Reproduce upgrade paths on staging data before production"],"tags":["database","panic","collections","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"}