From 443a26d7bbc63d3aa7189a8fce5617fac37d990f Mon Sep 17 00:00:00 2001 From: osmaczko <33099791+osmaczko@users.noreply.github.com> Date: Fri, 26 Jun 2026 17:30:44 +0200 Subject: [PATCH] feat: re-export ChatStorage and make storage_config fallible Callers that build an encrypted store had to depend on `libchat` directly for `ChatStorage`, and `ChatClientBuilder::storage_config` panicked on a bad config, which aborts the process under `panic = "abort"`. - Re-export `ChatStorage` from logos-chat so callers can name the store type without a direct `libchat` dependency. - `storage_config` now returns `Result<_, ChatError>` instead of `.expect()`, so an unopenable database surfaces as an error. Updates the chat-cli callers. --- bin/chat-cli/src/main.rs | 3 +++ crates/client/src/builder.rs | 13 +++++++------ crates/client/src/lib.rs | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/bin/chat-cli/src/main.rs b/bin/chat-cli/src/main.rs index 9a35b45..b36dbe3 100644 --- a/bin/chat-cli/src/main.rs +++ b/bin/chat-cli/src/main.rs @@ -119,6 +119,7 @@ fn run(transport: T, cli: &Cli) -> Result<()> { let (client, events) = ChatClientBuilder::new() .transport(transport) .storage_config(storage) + .map_err(|e| anyhow::anyhow!("{e:?}"))? .registration(registry) .build() .map_err(|e| anyhow::anyhow!("{e:?}")) @@ -129,6 +130,7 @@ fn run(transport: T, cli: &Cli) -> Result<()> { let (client, events) = ChatClientBuilder::new() .transport(transport) .storage_config(storage) + .map_err(|e| anyhow::anyhow!("{e:?}"))? .build() .map_err(|e| anyhow::anyhow!("{e:?}")) .context("failed to open chat client")?; @@ -197,6 +199,7 @@ fn run_logos_delivery(cli: Cli) -> Result<()> { path: db_str, key: "chat-cli".to_string(), }) + .map_err(|e| anyhow::anyhow!("{e:?}"))? .transport(delivery) .build() .map_err(|e| anyhow::anyhow!("{e:?}")) diff --git a/crates/client/src/builder.rs b/crates/client/src/builder.rs index e093dfe..c9dae6b 100644 --- a/crates/client/src/builder.rs +++ b/crates/client/src/builder.rs @@ -74,17 +74,18 @@ impl ChatClientBuilder { } } - pub fn storage_config(self, config: StorageConfig) -> ChatClientBuilder { - let storage = ChatStorage::new(config) - .map_err(ChatError::from) - .expect("Storage config file should be valid"); + pub fn storage_config( + self, + config: StorageConfig, + ) -> Result, ChatError> { + let storage = ChatStorage::new(config).map_err(ChatError::from)?; - ChatClientBuilder { + Ok(ChatClientBuilder { ident: self.ident, transport: self.transport, registration: self.registration, storage, - } + }) } } diff --git a/crates/client/src/lib.rs b/crates/client/src/lib.rs index becf852..d8b8f40 100644 --- a/crates/client/src/lib.rs +++ b/crates/client/src/lib.rs @@ -14,7 +14,7 @@ pub use event::{Event, MessageSender}; // Re-export types callers need to interact with ChatClient. pub use libchat::{ - AddressedEnvelope, ChatStore, ConversationClass, ConversationId, DeliveryService, + AddressedEnvelope, ChatStorage, ChatStore, ConversationClass, ConversationId, DeliveryService, IdentityProvider, RegistrationService, StorageConfig, };