{"record":{"id":"bb6b5f5936f846ef","repo":"dani-garcia/vaultwarden","slug":"error-filtering-events","errorCode":null,"errorMessage":"Error filtering events","messagePattern":"Error filtering events","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/db/models/event.rs","lineNumber":289,"sourceCode":"        .await\n    }\n\n    /// ##############\n    /// Custom Queries\n    pub async fn find_by_organization_uuid(\n        org_uuid: &OrganizationId,\n        start: &NaiveDateTime,\n        end: &NaiveDateTime,\n        conn: &DbConn,\n    ) -> Vec<Self> {\n        conn.run(move |conn| {\n            event::table\n                .filter(event::org_uuid.eq(org_uuid))\n                .filter(event::event_date.between(start, end))\n                .order_by(event::event_date.desc())\n                .limit(Self::PAGE_SIZE)\n                .load::<Self>(conn)\n                .expect(\"Error filtering events\")\n        })\n        .await\n    }\n\n    pub async fn count_by_org(org_uuid: &OrganizationId, conn: &DbConn) -> i64 {\n        conn.run(move |conn| {\n            event::table.filter(event::org_uuid.eq(org_uuid)).count().first::<i64>(conn).ok().unwrap_or(0)\n        })\n        .await\n    }\n\n    pub async fn find_by_org_and_member(\n        org_uuid: &OrganizationId,\n        member_uuid: &MembershipId,\n        start: &NaiveDateTime,\n        end: &NaiveDateTime,\n        conn: &DbConn,\n    ) -> Vec<Self> {","sourceCodeStart":271,"sourceCodeEnd":307,"githubUrl":"https://github.com/dani-garcia/vaultwarden/blob/cc67d644f62605cb46f4d16c4a2eed1a861cc8bb/src/db/models/event.rs#L271-L307","documentation":"Panic from `.expect()` on the Diesel `load` in `Event::find_by_organization_uuid`. The paged query for an organization's events within a date range failed at the database level, aborting the request. The crate deliberately panics because a failed audit-log read is considered unrecoverable in that path.","triggerScenarios":"Calling `Event::find_by_organization_uuid` with an unreachable DB, missing/renamed `event` table columns, or a `between(start, end)` date comparison the driver rejects (e.g. type mismatch on event_date).","commonSituations":"Schema drift after upgrading without migrations; DB connection dropped mid-request; querying an org whose events table partition is missing; SQLite file locked by another process.","solutions":["Check DB connectivity and DATABASE_URL settings","Apply pending migrations so the event table schema matches the code","Inspect logs for the underlying Diesel error behind the panic","Verify start/end parameters are valid datetime values accepted by the backend"],"exampleFix":"// before\n.load::<Self>(conn).expect(\"Error filtering events\")\n// after\n.load::<Self>(conn).unwrap_or_else(|e| { error!(\"event query failed: {e}\"); Vec::new() })","handlingStrategy":"try-catch","validationCode":"// validate date range before querying\nif start > end { return Err(\"invalid date range\"); }","typeGuard":null,"tryCatchPattern":"// guard the request path\nif !db_reachable().await { return fallback_empty_page(); }\nEvent::find_by_organization_uuid(org, start, end, &conn).await","preventionTips":["Run migrations automatically at startup (DB_INIT/enable migrations)","Validate datetime parameters before querying","Watch logs for repeated Diesel errors indicating schema drift","Test upgrades on a staging copy of the DB first"],"tags":["database","panic","events"],"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"}