spacedriveapp/spacedrive · error

Failed to create entry: {}

Error message

Failed to create entry: {}

What it means

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.

Source

Thrown at core/src/ops/indexing/change_detection/persistent.rs:248

		{
			// Cache the parent ID for future lookups
			state
				.entry_id_cache
				.insert(parent_path.to_path_buf(), parent_id);
			self.entry_id_cache
				.insert(parent_path.to_path_buf(), parent_id);
		}

		let entry_id = DatabaseStorage::create_entry(
			&mut state,
			&self.db,
			library.as_deref(),
			metadata,
			self.volume_id,
			parent_path,
		)
		.await
		.map_err(|e| anyhow::anyhow!("Failed to create entry: {}", e))?;

		self.entry_id_cache.insert(metadata.path.clone(), entry_id);

		let entry = entities::entry::Entity::find_by_id(entry_id)
			.one(&self.db)
			.await?
			.ok_or_else(|| anyhow::anyhow!("Entry not found after creation"))?;

		Ok(EntryRef {
			id: entry.id,
			uuid: entry.uuid,
			path: metadata.path.clone(),
			kind: metadata.kind,
		})
	}

	async fn update(&mut self, entry: &EntryRef, metadata: &DirEntry) -> Result<()> {
		use crate::ops::indexing::database_storage::DatabaseStorage;

View on GitHub (pinned to 6dfeccf211)

Solutions

  1. Inspect the wrapped inner error text: 'UNIQUE constraint failed' means the entry already exists (re-fetch instead of create)
  2. Deduplicate watcher events before they reach the create path
  3. If the parent is stale, invalidate entry_id_cache and re-resolve the parent before retrying
Defensive patterns

Strategy: try-catch

Try / catch

match DatabaseStorage::create_entry(&mut state, &self.db, library.as_deref(), metadata, self.volume_id, parent_path).await {
    Ok(id) => id,
    Err(e) if e.to_string().contains("UNIQUE") => {
        // entry already exists; re-fetch by path instead of failing
        return self.find_by_path(&metadata.path).await?.ok_or_else(|| e);
    }
    Err(e) => return Err(anyhow::anyhow!("Failed to create entry: {}", e)),
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of spacedriveapp/spacedrive@6dfeccf211 (2026-08-16). Data as JSON: /api/errors/914e5850541c605d. Report an issue: GitHub.