mirror of
https://github.com/logos-messaging/libchat.git
synced 2026-06-12 20:29:53 +00:00
25 lines
776 B
Rust
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}"))
|
||
|
|
}
|