fix: stop swallowing DB errors across the entire DAO layer

Every map_err(|_| DbError::new(...)) and map_err(|_| anyhow!("..."))
in the database layer was discarding the actual Diesel/SQLite error,
making failures impossible to diagnose from logs.

- Add DbError::log() that logs the source error before converting
- Replace all ~130 swallowed outer map_err closures with DbError::log
- Replace all ~47 swallowed inner anyhow closures to include the
  source error in the message

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Cameron CordesandClaude Opus 4.7 committed 2026-05-27 13:56:48 -04:00
1 parent 39ad83f55b
commit dad0220587
10 files changed
+174 -169

No files matched your search

+7 -7
View File
@@ -227,7 +227,7 @@ impl SearchHistoryDao for SqliteSearchHistoryDao {
source_file: search.source_file,
})
})
.map_err(|_| DbError::new(DbErrorKind::InsertError))
.map_err(|e| DbError::log(DbErrorKind::InsertError, e))
}
fn store_searches_batch(
@@ -283,7 +283,7 @@ impl SearchHistoryDao for SqliteSearchHistoryDao {
Ok(inserted)
})
.map_err(|_| DbError::new(DbErrorKind::InsertError))
.map_err(|e| DbError::log(DbErrorKind::InsertError, e))
}
fn find_searches_in_range(
@@ -310,7 +310,7 @@ impl SearchHistoryDao for SqliteSearchHistoryDao {
.map(|rows| rows.into_iter().map(|r| r.to_search_record()).collect())
.map_err(|e| anyhow::anyhow!("Query error: {:?}", e))
})
.map_err(|_| DbError::new(DbErrorKind::QueryError))
.map_err(|e| DbError::log(DbErrorKind::QueryError, e))
}
fn find_similar_searches(
@@ -372,7 +372,7 @@ impl SearchHistoryDao for SqliteSearchHistoryDao {
.map(|(_, search)| search)
.collect())
})
.map_err(|_| DbError::new(DbErrorKind::QueryError))
.map_err(|e| DbError::log(DbErrorKind::QueryError, e))
}
fn find_relevant_searches_hybrid(
@@ -459,7 +459,7 @@ impl SearchHistoryDao for SqliteSearchHistoryDao {
.collect())
}
})
.map_err(|_| DbError::new(DbErrorKind::QueryError))
.map_err(|e| DbError::log(DbErrorKind::QueryError, e))
}
fn search_exists(
@@ -490,7 +490,7 @@ impl SearchHistoryDao for SqliteSearchHistoryDao {
Ok(result.count > 0)
})
.map_err(|_| DbError::new(DbErrorKind::QueryError))
.map_err(|e| DbError::log(DbErrorKind::QueryError, e))
}
fn get_search_count(&mut self, context: &opentelemetry::Context) -> Result<i64, DbError> {
@@ -513,6 +513,6 @@ impl SearchHistoryDao for SqliteSearchHistoryDao {
Ok(result.count)
})
.map_err(|_| DbError::new(DbErrorKind::QueryError))
.map_err(|e| DbError::log(DbErrorKind::QueryError, e))
}
}