libchat/core/sqlite/src/errors.rs
kaichao c44c52b127
feat: storage implementation and trait abstraction (#79)
* feat: storage for conversations

* fix: db types conversion

* feat: run migrations from sql files

* feat: persist identity

* fix: revert double ratchet storage refactor

* fix: clean

* refactor: use result wrapper for ffi

* refactor: uniform storage error into chat error

* fix: zeroize identity record

* fix: zeroize for secret keys in db operations

* fix: transactional sql migration

* fix: remove destroy_string

* feat: db storage for inbox ephermeral keys

* chore: remove in memory hashmap for ephemeral keys

* feat: persist conversation store

* feat: wire with the double ratchet storage

* feat: remove conversation store

* chore: fix conversation type not used

* feat: mock chat store implementation

* chore: sqlite module

* feat: sqlite crate

* chore: sqlite rename

* chore: more refactor

* extract ratchet store trait

* chore: clear error conversion

* chore: remove customized db conn

* chore: fix clippy

* chore: refactor to use generics and enum

* chore: further clean for review comments
2026-04-03 08:25:26 +08:00

25 lines
776 B
Rust

use rusqlite::Error as RusqliteError;
use storage::StorageError;
pub(crate) fn map_rusqlite_error(err: RusqliteError) -> StorageError {
StorageError::Database(err.to_string())
}
pub(crate) fn map_optional_row<T>(
result: Result<T, RusqliteError>,
) -> Result<Option<T>, StorageError> {
match result {
Ok(value) => Ok(Some(value)),
Err(RusqliteError::QueryReturnedNoRows) => Ok(None),
Err(err) => Err(map_rusqlite_error(err)),
}
}
pub(crate) fn not_found(record: impl Into<String>) -> StorageError {
StorageError::NotFound(record.into())
}
pub(crate) fn invalid_blob_length(field: &str, expected: usize, actual: usize) -> StorageError {
StorageError::InvalidData(format!("{field} expected {expected} bytes, got {actual}"))
}