mirror of
https://github.com/logos-messaging/libchat.git
synced 2026-03-27 06:33:08 +00:00
refactor: uniform storage error into chat error
This commit is contained in:
parent
3673d730f3
commit
fdacfae108
@ -66,7 +66,9 @@ pub fn create_context(name: repr_c::String) -> repr_c::Box<ContextHandle> {
|
||||
/// - db_path: Path to the SQLite database file
|
||||
///
|
||||
/// # Returns
|
||||
/// CResult with context handle on success, or error string on failure
|
||||
/// CResult with context handle on success, or error string on failure.
|
||||
/// On success, the context handle must be freed with `destroy_context()` after usage.
|
||||
/// On error, the error string must be freed with `destroy_string()` after usage.
|
||||
#[ffi_export]
|
||||
pub fn create_context_with_storage(
|
||||
name: repr_c::String,
|
||||
|
||||
@ -8,20 +8,13 @@ use crate::{
|
||||
identity::Identity,
|
||||
inbox::Inbox,
|
||||
proto::{EncryptedPayload, EnvelopeV1, Message},
|
||||
storage::{ChatStorage, StorageError},
|
||||
storage::ChatStorage,
|
||||
types::{AddressedEnvelope, ContentData},
|
||||
};
|
||||
|
||||
pub use crate::conversation::ConversationIdOwned;
|
||||
pub use crate::inbox::Introduction;
|
||||
|
||||
/// Error type for Context operations.
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum ContextError {
|
||||
#[error("storage error: {0}")]
|
||||
Storage(#[from] StorageError),
|
||||
}
|
||||
|
||||
// This is the main entry point to the conversations api.
|
||||
// Ctx manages lifetimes of objects to process and generate payloads.
|
||||
pub struct Context {
|
||||
@ -37,7 +30,7 @@ impl Context {
|
||||
///
|
||||
/// If an identity exists in storage, it will be restored.
|
||||
/// Otherwise, a new identity will be created with the given name and saved.
|
||||
pub fn open(name: impl Into<String>, config: StorageConfig) -> Result<Self, ContextError> {
|
||||
pub fn open(name: impl Into<String>, config: StorageConfig) -> Result<Self, ChatError> {
|
||||
let mut storage = ChatStorage::new(config)?;
|
||||
let name = name.into();
|
||||
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
pub use thiserror::Error;
|
||||
|
||||
use storage::StorageError;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum ChatError {
|
||||
#[error("protocol error: {0:?}")]
|
||||
@ -20,6 +22,8 @@ pub enum ChatError {
|
||||
BadParsing(&'static str),
|
||||
#[error("convo with id: {0} was not found")]
|
||||
NoConvo(String),
|
||||
#[error("storage error: {0}")]
|
||||
Storage(#[from] StorageError),
|
||||
}
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
|
||||
@ -8,6 +8,6 @@ pub struct CResult<T: ReprC, Err: ReprC> {
|
||||
}
|
||||
|
||||
#[ffi_export]
|
||||
pub fn ffi_c_string_free(s: repr_c::String) {
|
||||
pub fn destroy_string(s: repr_c::String) {
|
||||
drop(s);
|
||||
}
|
||||
|
||||
@ -5,4 +5,3 @@ mod migrations;
|
||||
pub(crate) mod types;
|
||||
|
||||
pub(crate) use db::ChatStorage;
|
||||
pub(crate) use storage::StorageError;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user