dani-garcia/vaultwarden · critical

Error loading collections

Error message

Error loading collections

What it means

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.

Solutions

  1. Run database migrations to create/upgrade groups and collections_groups tables
  2. Log the underlying diesel error before the expect to see the true cause
  3. Verify DB connectivity and credentials
  4. If groups are not needed, disable org groups in config so the simpler query branch runs
  5. Restore the schema to match the compiled models
Defensive patterns

Strategy: try-catch

Validate before calling

// If enabling org groups, first verify group tables exist (SQLite)
let ok = conn.run(|c| diesel::select(diesel::dsl::sql::<diesel::sql_types::Bool>(
    "SELECT EXISTS(SELECT 1 FROM sqlite_master WHERE name='collections_groups')"
)).load::<bool>(c)).await.unwrap_or(vec![false]).into_iter().next().unwrap_or(false);
if !ok { panic!("ORG_GROUPS_ENABLED but group tables missing; run migrations"); }

Try / catch

let r = std::panic::catch_unwind(std::panic::AssertUnwindSafe(async {
    Collection::find_by_user_uuid(&user_uuid, &conn).await
}));
if r.is_err() { log::error!("collection lookup for user panicked; check group tables/migrations"); }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.

Related errors


AI-assisted analysis of dani-garcia/vaultwarden@cc67d644f6 (2026-09-19). Data as JSON: /api/errors/b138188852ec36b6. Report an issue: GitHub.

Appendix: source

Thrown at src/db/models/collection.rs:271

                            .eq(user_uuid)
                            .or(
                                // Directly accessed collection
                                users_organizations::access_all.eq(true), // access_all in Organization
                            )
                            .or(
                                groups::access_all.eq(true), // access_all in groups
                            )
                            .or(
                                // access via groups
                                groups_users::users_organizations_uuid
                                    .eq(users_organizations::uuid)
                                    .and(collections_groups::collections_uuid.is_not_null()),
                            ),
                    )
                    .select(collections::all_columns)
                    .distinct()
                    .load::<Self>(conn)
                    .expect("Error loading collections")
            })
            .await
        } else {
            conn.run(move |conn| {
                collections::table
                    .left_join(
                        users_collections::table.on(users_collections::collection_uuid
                            .eq(collections::uuid)
                            .and(users_collections::user_uuid.eq(user_uuid.clone()))),
                    )
                    .left_join(
                        users_organizations::table.on(collections::org_uuid
                            .eq(users_organizations::org_uuid)
                            .and(users_organizations::user_uuid.eq(user_uuid.clone()))),
                    )
                    .filter(users_organizations::status.eq(MembershipStatus::Confirmed as i32))
                    .filter(users_collections::user_uuid.eq(user_uuid).or(
                        // Directly accessed collection

View on GitHub (pinned to cc67d644f6)