From 39ad83f55b524a54f125883f9b8c38f2cc8cf0c4 Mon Sep 17 00:00:00 2001 From: Cameron Cordes Date: Wed, 27 May 2026 13:53:54 -0400 Subject: [PATCH] fix: surface actual Diesel error in store_insight instead of generic InsertError The previous map_err closures discarded the Diesel error, making failures like missing columns impossible to diagnose from logs. Now the underlying error is logged before converting to DbError. Co-Authored-By: Claude Opus 4.7 (1M context) --- src/database/insights_dao.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/database/insights_dao.rs b/src/database/insights_dao.rs index 2ca214c..25b1690 100644 --- a/src/database/insights_dao.rs +++ b/src/database/insights_dao.rs @@ -161,13 +161,13 @@ impl InsightDao for SqliteInsightDao { ) .set(is_current.eq(false)) .execute(connection.deref_mut()) - .map_err(|_| anyhow::anyhow!("Update is_current error"))?; + .map_err(|e| anyhow::anyhow!("Failed to flip is_current: {}", e))?; // Insert the new insight as current diesel::insert_into(photo_insights) .values(&insight) .execute(connection.deref_mut()) - .map_err(|_| anyhow::anyhow!("Insert error"))?; + .map_err(|e| anyhow::anyhow!("Failed to insert insight: {}", e))?; // Retrieve the inserted record (is_current = true) photo_insights @@ -175,9 +175,12 @@ impl InsightDao for SqliteInsightDao { .filter(rel_path.eq(&insight.file_path)) .filter(is_current.eq(true)) .first::(connection.deref_mut()) - .map_err(|_| anyhow::anyhow!("Query error")) + .map_err(|e| anyhow::anyhow!("Failed to retrieve inserted insight: {}", e)) + }) + .map_err(|e| { + log::error!("store_insight failed: {}", e); + DbError::new(DbErrorKind::InsertError) }) - .map_err(|_| DbError::new(DbErrorKind::InsertError)) } fn get_insight(