{"record":{"id":"914e5850541c605d","repo":"spacedriveapp/spacedrive","slug":"failed-to-create-entry","errorCode":null,"errorMessage":"Failed to create entry: {}","messagePattern":"Failed to create entry: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/src/ops/indexing/change_detection/persistent.rs","lineNumber":248,"sourceCode":"\t\t{\n\t\t\t// Cache the parent ID for future lookups\n\t\t\tstate\n\t\t\t\t.entry_id_cache\n\t\t\t\t.insert(parent_path.to_path_buf(), parent_id);\n\t\t\tself.entry_id_cache\n\t\t\t\t.insert(parent_path.to_path_buf(), parent_id);\n\t\t}\n\n\t\tlet entry_id = DatabaseStorage::create_entry(\n\t\t\t&mut state,\n\t\t\t&self.db,\n\t\t\tlibrary.as_deref(),\n\t\t\tmetadata,\n\t\t\tself.volume_id,\n\t\t\tparent_path,\n\t\t)\n\t\t.await\n\t\t.map_err(|e| anyhow::anyhow!(\"Failed to create entry: {}\", e))?;\n\n\t\tself.entry_id_cache.insert(metadata.path.clone(), entry_id);\n\n\t\tlet entry = entities::entry::Entity::find_by_id(entry_id)\n\t\t\t.one(&self.db)\n\t\t\t.await?\n\t\t\t.ok_or_else(|| anyhow::anyhow!(\"Entry not found after creation\"))?;\n\n\t\tOk(EntryRef {\n\t\t\tid: entry.id,\n\t\t\tuuid: entry.uuid,\n\t\t\tpath: metadata.path.clone(),\n\t\t\tkind: metadata.kind,\n\t\t})\n\t}\n\n\tasync fn update(&mut self, entry: &EntryRef, metadata: &DirEntry) -> Result<()> {\n\t\tuse crate::ops::indexing::database_storage::DatabaseStorage;","sourceCodeStart":230,"sourceCodeEnd":266,"githubUrl":"https://github.com/spacedriveapp/spacedrive/blob/6dfeccf2113039e35f2ce735f945e70dc3e4ea45/core/src/ops/indexing/change_detection/persistent.rs#L230-L266","documentation":"DatabaseStorage::create_entry failed while the adapter tried to create a new entry during change detection; the original sea_orm error is stringified into this message. Common underlying causes are a unique-constraint violation (path or uuid already present), a missing parent FK, or database contention, because the parent id was just resolved through the entry_id_cache.","triggerScenarios":"Two workers creating the same path simultaneously (duplicate event delivery); cached parent id referencing a deleted row; unique index conflict on entry uuid; DB lock timeout under heavy concurrent indexing.","commonSituations":"Watcher emitting duplicate create events; indexer and change-detection racing on a new directory; retry after a partial earlier failure that already inserted the row.","solutions":["Inspect the wrapped inner error text: 'UNIQUE constraint failed' means the entry already exists (re-fetch instead of create)","Deduplicate watcher events before they reach the create path","If the parent is stale, invalidate entry_id_cache and re-resolve the parent before retrying"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match DatabaseStorage::create_entry(&mut state, &self.db, library.as_deref(), metadata, self.volume_id, parent_path).await {\n    Ok(id) => id,\n    Err(e) if e.to_string().contains(\"UNIQUE\") => {\n        // entry already exists; re-fetch by path instead of failing\n        return self.find_by_path(&metadata.path).await?.ok_or_else(|| e);\n    }\n    Err(e) => return Err(anyhow::anyhow!(\"Failed to create entry: {}\", e)),\n}","preventionTips":["Deduplicate watcher create events before they reach storage","Log the parent path and entry path on create failures for constraint diagnosis","Serialize per-directory writes to avoid duplicate-create races"],"tags":["indexing","database","create","constraint","change-detection"],"backgroundTag":null,"analyzedSha":"6dfeccf2113039e35f2ce735f945e70dc3e4ea45","analyzedAt":"2026-08-16T11:26:17.074Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}