{"record":{"id":"00c07fdb81183f6a","repo":"dani-garcia/vaultwarden","slug":"error-loading-org-policy","errorCode":null,"errorMessage":"Error loading org_policy","messagePattern":"Error loading org_policy","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/db/models/org_policy.rs","lineNumber":169,"sourceCode":"            }\n        }\n    }\n\n    pub async fn delete(self, conn: &DbConn) -> EmptyResult {\n        conn.run(move |conn| {\n            diesel::delete(org_policies::table.filter(org_policies::uuid.eq(self.uuid)))\n                .execute(conn)\n                .map_res(\"Error deleting org_policy\")\n        })\n        .await\n    }\n\n    pub async fn find_by_org(org_uuid: &OrganizationId, conn: &DbConn) -> Vec<Self> {\n        conn.run(move |conn| {\n            org_policies::table\n                .filter(org_policies::org_uuid.eq(org_uuid))\n                .load::<Self>(conn)\n                .expect(\"Error loading org_policy\")\n        })\n        .await\n    }\n\n    pub async fn find_confirmed_by_user(user_uuid: &UserId, conn: &DbConn) -> Vec<Self> {\n        conn.run(move |conn| {\n            org_policies::table\n                .inner_join(\n                    users_organizations::table.on(users_organizations::org_uuid\n                        .eq(org_policies::org_uuid)\n                        .and(users_organizations::user_uuid.eq(user_uuid))),\n                )\n                .filter(users_organizations::status.eq(MembershipStatus::Confirmed as i32))\n                .select(org_policies::all_columns)\n                .load::<Self>(conn)\n                .expect(\"Error loading org_policy\")\n        })\n        .await","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/dani-garcia/vaultwarden/blob/cc67d644f62605cb46f4d16c4a2eed1a861cc8bb/src/db/models/org_policy.rs#L151-L187","documentation":"Panic raised in OrgPolicy::find_by_org: the query loading all org_policies rows filtered by org_uuid is unwrapped with .expect(). An organization with no policies returns an empty vec and does not trigger this; the panic fires only when the SQL fails - a dead connection, missing/mismatched org_policies schema, or a row that fails to deserialize into the OrgPolicy model.","triggerScenarios":"Thrown at src/db/models/org_policy.rs:169 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify database availability and connection pool health","Confirm the org_policies table schema matches the OrgPolicy model via migrations","Capture the diesel error from the panic message to diagnose the exact SQL problem","Replace .expect with .map_res so the caller receives an ApiError rather than a panic"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}