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(