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.
This commit is contained in:
osmaczko 2026-06-26 17:30:44 +02:00
parent 0d38dd80b7
commit 443a26d7bb
No known key found for this signature in database
GPG Key ID: 28DEFC027B185BB8
3 changed files with 11 additions and 7 deletions

View File

@ -119,6 +119,7 @@ fn run<T: Transport>(transport: T, cli: &Cli) -> Result<()> {
let (client, events) = ChatClientBuilder::new() let (client, events) = ChatClientBuilder::new()
.transport(transport) .transport(transport)
.storage_config(storage) .storage_config(storage)
.map_err(|e| anyhow::anyhow!("{e:?}"))?
.registration(registry) .registration(registry)
.build() .build()
.map_err(|e| anyhow::anyhow!("{e:?}")) .map_err(|e| anyhow::anyhow!("{e:?}"))
@ -129,6 +130,7 @@ fn run<T: Transport>(transport: T, cli: &Cli) -> Result<()> {
let (client, events) = ChatClientBuilder::new() let (client, events) = ChatClientBuilder::new()
.transport(transport) .transport(transport)
.storage_config(storage) .storage_config(storage)
.map_err(|e| anyhow::anyhow!("{e:?}"))?
.build() .build()
.map_err(|e| anyhow::anyhow!("{e:?}")) .map_err(|e| anyhow::anyhow!("{e:?}"))
.context("failed to open chat client")?; .context("failed to open chat client")?;
@ -197,6 +199,7 @@ fn run_logos_delivery(cli: Cli) -> Result<()> {
path: db_str, path: db_str,
key: "chat-cli".to_string(), key: "chat-cli".to_string(),
}) })
.map_err(|e| anyhow::anyhow!("{e:?}"))?
.transport(delivery) .transport(delivery)
.build() .build()
.map_err(|e| anyhow::anyhow!("{e:?}")) .map_err(|e| anyhow::anyhow!("{e:?}"))

View File

@ -74,17 +74,18 @@ impl<I, T, R, S> ChatClientBuilder<I, T, R, S> {
} }
} }
pub fn storage_config(self, config: StorageConfig) -> ChatClientBuilder<I, T, R, ChatStorage> { pub fn storage_config(
let storage = ChatStorage::new(config) self,
.map_err(ChatError::from) config: StorageConfig,
.expect("Storage config file should be valid"); ) -> Result<ChatClientBuilder<I, T, R, ChatStorage>, ChatError> {
let storage = ChatStorage::new(config).map_err(ChatError::from)?;
ChatClientBuilder { Ok(ChatClientBuilder {
ident: self.ident, ident: self.ident,
transport: self.transport, transport: self.transport,
registration: self.registration, registration: self.registration,
storage, storage,
} })
} }
} }

View File

@ -14,7 +14,7 @@ pub use event::{Event, MessageSender};
// Re-export types callers need to interact with ChatClient. // Re-export types callers need to interact with ChatClient.
pub use libchat::{ pub use libchat::{
AddressedEnvelope, ChatStore, ConversationClass, ConversationId, DeliveryService, AddressedEnvelope, ChatStorage, ChatStore, ConversationClass, ConversationId, DeliveryService,
IdentityProvider, RegistrationService, StorageConfig, IdentityProvider, RegistrationService, StorageConfig,
}; };