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) <noreply@anthropic.com>
This commit is contained in:
Cameron Cordes
2026-05-27 13:53:54 -04:00
parent 9654d256f4
commit 39ad83f55b
+7 -4
View File
@@ -161,13 +161,13 @@ impl InsightDao for SqliteInsightDao {
) )
.set(is_current.eq(false)) .set(is_current.eq(false))
.execute(connection.deref_mut()) .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 // Insert the new insight as current
diesel::insert_into(photo_insights) diesel::insert_into(photo_insights)
.values(&insight) .values(&insight)
.execute(connection.deref_mut()) .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) // Retrieve the inserted record (is_current = true)
photo_insights photo_insights
@@ -175,9 +175,12 @@ impl InsightDao for SqliteInsightDao {
.filter(rel_path.eq(&insight.file_path)) .filter(rel_path.eq(&insight.file_path))
.filter(is_current.eq(true)) .filter(is_current.eq(true))
.first::<PhotoInsight>(connection.deref_mut()) .first::<PhotoInsight>(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( fn get_insight(