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()
.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<T: Transport>(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:?}"))

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> {
let storage = ChatStorage::new(config)
.map_err(ChatError::from)
.expect("Storage config file should be valid");
pub fn storage_config(
self,
config: StorageConfig,
) -> Result<ChatClientBuilder<I, T, R, ChatStorage>, ChatError> {
let storage = ChatStorage::new(config).map_err(ChatError::from)?;
ChatClientBuilder {
Ok(ChatClientBuilder {
ident: self.ident,
transport: self.transport,
registration: self.registration,
storage,
}
})
}
}

View File

@ -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,
};