spacedriveapp/spacedrive · error · anyhow::Error
Failed to query library devices: {}
Error message
Failed to query library devices: {} What it means
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.
Source
Thrown at core/src/service/network/transports/sync.rs:338
///
/// Returns device UUIDs that are:
/// 1. Members of this specific library (in devices table)
/// 2. Have sync_enabled=true in this library
/// 3. Currently network-connected (according to Iroh)
async fn get_connected_sync_partners(
&self,
library_id: Uuid,
db: &sea_orm::DatabaseConnection,
) -> Result<Vec<Uuid>> {
use crate::infra::db::entities;
use sea_orm::{ColumnTrait, EntityTrait, QueryFilter};
// 1. Query devices table for THIS library with sync_enabled=true
let library_devices = entities::device::Entity::find()
.filter(entities::device::Column::SyncEnabled.eq(true))
.all(db)
.await
.map_err(|e| anyhow::anyhow!("Failed to query library devices: {}", e))?;
// 2. Get our own device ID to exclude from partners
let our_device_id = self.device_id();
// 3. Get Iroh endpoint for checking connection state
let endpoint = self
.endpoint()
.ok_or_else(|| anyhow::anyhow!("Network endpoint not initialized"))?;
// 4. Get DeviceRegistry to check which devices have NodeId mappings (paired devices)
let device_registry_arc = self.device_registry();
let registry = device_registry_arc.read().await;
// 5. Filter to OTHER devices in this library that are paired
// We don't check Iroh connection state because:
// - Connections may be idle (no active streams) but still reachable
// - send_sync_message establishes connections on-demand
// - Better to attempt send and handle failure than skip paired devicesView on GitHub (pinned to 6dfeccf211)
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
Defensive patterns
Strategy: try-catch
Validate before calling
// Ensure the schema is present before querying sync partners assert!(db.ping().await.is_ok()); assert!(Migrator::is_applied(db, Migration::AddSyncEnabledToDevice).await.unwrap_or(false));
Try / catch
match entities::device::Entity::find().filter(...).all(db).await {
Err(e) if e.to_string().contains("no such table") => {
// run migrations, then retry the query once
}
other => other,
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Fresh installs, partial upgrades, or a daemon restart racing a still-open library handle.
Related errors
- Invalid event type: {}
- Invalid category: {}
- Invalid severity: {}
- Failed to initialize core: error code ${result}
- Library with ID '${libraryId}' not found
AI-assisted analysis of spacedriveapp/spacedrive@6dfeccf211 (2026-08-16).
Data as JSON: /api/errors/9ec5a744ac9bbe7f.
Report an issue: GitHub.