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 Cordes
2026-05-27 13:56:48 -04:00
parent 39ad83f55b
commit dad0220587
10 changed files with 174 additions and 169 deletions
+6 -6
View File
@@ -119,7 +119,7 @@ impl PersonaDao for SqlitePersonaDao {
.load::<Persona>(conn.deref_mut())
.map_err(|e| anyhow::anyhow!("Query error: {}", e))
})
.map_err(|_| DbError::new(DbErrorKind::QueryError))
.map_err(|e| DbError::log(DbErrorKind::QueryError, e))
}
fn get_persona(
@@ -138,7 +138,7 @@ impl PersonaDao for SqlitePersonaDao {
.optional()
.map_err(|e| anyhow::anyhow!("Query error: {}", e))
})
.map_err(|_| DbError::new(DbErrorKind::QueryError))
.map_err(|e| DbError::log(DbErrorKind::QueryError, e))
}
fn create_persona(
@@ -178,7 +178,7 @@ impl PersonaDao for SqlitePersonaDao {
.first::<Persona>(conn.deref_mut())
.map_err(|e| anyhow::anyhow!("Query error: {}", e))
})
.map_err(|_| DbError::new(DbErrorKind::InsertError))
.map_err(|e| DbError::log(DbErrorKind::InsertError, e))
}
fn update_persona(
@@ -241,7 +241,7 @@ impl PersonaDao for SqlitePersonaDao {
.optional()
.map_err(|e| anyhow::anyhow!("Query error: {}", e))
})
.map_err(|_| DbError::new(DbErrorKind::UpdateError))
.map_err(|e| DbError::log(DbErrorKind::UpdateError, e))
}
fn delete_persona(
@@ -258,7 +258,7 @@ impl PersonaDao for SqlitePersonaDao {
.map_err(|e| anyhow::anyhow!("Delete error: {}", e))?;
Ok(n > 0)
})
.map_err(|_| DbError::new(DbErrorKind::QueryError))
.map_err(|e| DbError::log(DbErrorKind::QueryError, e))
}
fn bulk_import(
@@ -294,7 +294,7 @@ impl PersonaDao for SqlitePersonaDao {
}
Ok(inserted)
})
.map_err(|_| DbError::new(DbErrorKind::InsertError))
.map_err(|e| DbError::log(DbErrorKind::InsertError, e))
}
}