{"record":{"id":"9ec5a744ac9bbe7f","repo":"spacedriveapp/spacedrive","slug":"failed-to-query-library-devices","errorCode":null,"errorMessage":"Failed to query library devices: {}","messagePattern":"Failed to query library devices: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"core/src/service/network/transports/sync.rs","lineNumber":338,"sourceCode":"\t///\n\t/// Returns device UUIDs that are:\n\t/// 1. Members of this specific library (in devices table)\n\t/// 2. Have sync_enabled=true in this library\n\t/// 3. Currently network-connected (according to Iroh)\n\tasync fn get_connected_sync_partners(\n\t\t&self,\n\t\tlibrary_id: Uuid,\n\t\tdb: &sea_orm::DatabaseConnection,\n\t) -> Result<Vec<Uuid>> {\n\t\tuse crate::infra::db::entities;\n\t\tuse sea_orm::{ColumnTrait, EntityTrait, QueryFilter};\n\n\t\t// 1. Query devices table for THIS library with sync_enabled=true\n\t\tlet library_devices = entities::device::Entity::find()\n\t\t\t.filter(entities::device::Column::SyncEnabled.eq(true))\n\t\t\t.all(db)\n\t\t\t.await\n\t\t\t.map_err(|e| anyhow::anyhow!(\"Failed to query library devices: {}\", e))?;\n\n\t\t// 2. Get our own device ID to exclude from partners\n\t\tlet our_device_id = self.device_id();\n\n\t\t// 3. Get Iroh endpoint for checking connection state\n\t\tlet endpoint = self\n\t\t\t.endpoint()\n\t\t\t.ok_or_else(|| anyhow::anyhow!(\"Network endpoint not initialized\"))?;\n\n\t\t// 4. Get DeviceRegistry to check which devices have NodeId mappings (paired devices)\n\t\tlet device_registry_arc = self.device_registry();\n\t\tlet registry = device_registry_arc.read().await;\n\n\t\t// 5. Filter to OTHER devices in this library that are paired\n\t\t// We don't check Iroh connection state because:\n\t\t// - Connections may be idle (no active streams) but still reachable\n\t\t// - send_sync_message establishes connections on-demand\n\t\t// - Better to attempt send and handle failure than skip paired devices","sourceCodeStart":320,"sourceCodeEnd":356,"githubUrl":"https://github.com/spacedriveapp/spacedrive/blob/6dfeccf2113039e35f2ce735f945e70dc3e4ea45/core/src/service/network/transports/sync.rs#L320-L356","documentation":"The SeaORM query on the device table filtered by SyncEnabled.eq(true) failed at the database layer inside get_connected_sync_partners; the formatted message carries the DbErr. Typical roots: the database connection was closed, migrations never created the expected table or column, or the SQLite file is locked or corrupted.","triggerScenarios":"Calling the partner listing before library migrations ran; the library database was closed while the query was in flight; concurrent writers holding the SQLite lock beyond the busy timeout; a schema older than the code expects.","commonSituations":"Fresh installs, partial upgrades, or a daemon restart racing a still-open library handle.","solutions":["Run pending migrations for the library before any sync or partner queries","Verify the device table exists and has the sync_enabled column in the library database","For SQLite, enable WAL and keep write transactions short so reader queries do not hit locks","Check that the library and its DatabaseConnection are still open when the query executes"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Ensure the schema is present before querying sync partners\nassert!(db.ping().await.is_ok());\nassert!(Migrator::is_applied(db, Migration::AddSyncEnabledToDevice).await.unwrap_or(false));","typeGuard":null,"tryCatchPattern":"match entities::device::Entity::find().filter(...).all(db).await {\n    Err(e) if e.to_string().contains(\"no such table\") => {\n        // run migrations, then retry the query once\n    }\n    other => other,\n}","preventionTips":["Run migrations at library open before any sync queries","Enable WAL on SQLite and keep write transactions short","Do not query a library whose DatabaseConnection has been closed"],"tags":["database","sea-orm","sync","migration","sqlite"],"backgroundTag":null,"analyzedSha":"6dfeccf2113039e35f2ce735f945e70dc3e4ea45","analyzedAt":"2026-08-16T11:26:17.074Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}