{"record":{"id":"44dcd8bb595cb351","repo":"spacedriveapp/spacedrive","slug":"library-not-found-44dcd8","errorCode":null,"errorMessage":"Library not found: {}","messagePattern":"Library not found: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/src/ops/indexing/change_detection/persistent.rs","lineNumber":52,"sourceCode":"\tlocation_root_entry_id: i32,\n\tvolume_id: i32,\n\tdb: sea_orm::DatabaseConnection,\n\tvolume_backend: Option<Arc<dyn crate::volume::VolumeBackend>>,\n\tentry_id_cache: HashMap<PathBuf, i32>,\n}\n\nimpl DatabaseAdapter {\n\tpub async fn new(\n\t\tcontext: Arc<CoreContext>,\n\t\tlibrary_id: Uuid,\n\t\tlocation_id: Uuid,\n\t\t_location_root: &Path,\n\t\tvolume_backend: Option<Arc<dyn crate::volume::VolumeBackend>>,\n\t) -> Result<Self> {\n\t\tlet library = context\n\t\t\t.get_library(library_id)\n\t\t\t.await\n\t\t\t.ok_or_else(|| anyhow::anyhow!(\"Library not found: {}\", library_id))?;\n\n\t\tlet db = library.db().conn().clone();\n\n\t\tlet location_record = entities::location::Entity::find()\n\t\t\t.filter(entities::location::Column::Uuid.eq(location_id))\n\t\t\t.one(&db)\n\t\t\t.await?\n\t\t\t.ok_or_else(|| anyhow::anyhow!(\"Location not found: {}\", location_id))?;\n\n\t\tlet location_root_entry_id = location_record\n\t\t\t.entry_id\n\t\t\t.ok_or_else(|| anyhow::anyhow!(\"Location {} has no root entry\", location_id))?;\n\n\t\tlet volume_id = location_record.volume_id.ok_or_else(|| {\n\t\t\tanyhow::anyhow!(\n\t\t\t\t\"Location {} has no volume_id - volume must be detected before change detection\",\n\t\t\t\tlocation_id\n\t\t\t)","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/spacedriveapp/spacedrive/blob/6dfeccf2113039e35f2ce735f945e70dc3e4ea45/core/src/ops/indexing/change_detection/persistent.rs#L34-L70","documentation":"DatabaseAdapter::new resolves the library through CoreContext::get_library(library_id) before opening its DB connection for persistent change detection. When that lookup returns None, this error is thrown: the library_id is not registered in the running daemon's library map. Change detection cannot proceed because every subsequent query would target a nonexistent database.","triggerScenarios":"Constructing DatabaseAdapter with a stale or wrong library_id; a library deleted from another client while a change-detection job was queued; daemon restarted and the library not yet reloaded before the job re-ran.","commonSituations":"Job queue retains a library_id across daemon restarts; typo or UUID parse issue producing a valid-but-unknown id; library deleted concurrently with an indexer start.","solutions":["Confirm the library exists in this daemon before constructing the adapter (see validation code)","If the daemon was just restarted, wait for library load/registration to finish before scheduling indexing jobs","If the library was deleted, drop the queued job instead of retrying it","Check that the library_id flows from the same source that created the library (no serialization truncation)"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Resolve the library before constructing the adapter\nlet Some(library) = context.get_library(library_id).await else {\n    tracing::warn!(%library_id, \"skipping change detection: library not loaded\");\n    return Ok(());\n};\n// now safe: DatabaseAdapter::new(context, library_id, ...).await","typeGuard":null,"tryCatchPattern":"if let Err(e) = DatabaseAdapter::new(context.clone(), library_id, location_id, &root, backend).await {\n    if e.to_string().contains(\"Library not found\") {\n        // drop the job; the library no longer exists in this daemon\n        return Ok(());\n    }\n    return Err(e);\n}","preventionTips":["Never persist library ids in durable job queues without revalidating them at dequeue time","Ensure daemon library loading completes before indexing jobs are scheduled","Delete queued indexing jobs as part of library deletion"],"tags":["indexing","database","library","lifecycle","change-detection"],"backgroundTag":null,"analyzedSha":"6dfeccf2113039e35f2ce735f945e70dc3e4ea45","analyzedAt":"2026-08-16T11:26:17.074Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}