ffi: Move error type into its own module

This commit is contained in:
Jonas Platte
2023-04-05 12:02:53 +02:00
committed by Jonas Platte
parent 4f316a130f
commit 9ffcb8bc8a
2 changed files with 48 additions and 47 deletions

View File

@@ -0,0 +1,43 @@
use matrix_sdk::{self, encryption::CryptoStoreError, HttpError, IdParseError};
#[derive(thiserror::Error, Debug)]
pub enum ClientError {
#[error("client error: {msg}")]
Generic { msg: String },
}
impl From<anyhow::Error> for ClientError {
fn from(e: anyhow::Error) -> ClientError {
ClientError::Generic { msg: e.to_string() }
}
}
impl From<matrix_sdk::Error> for ClientError {
fn from(e: matrix_sdk::Error) -> Self {
anyhow::Error::from(e).into()
}
}
impl From<CryptoStoreError> for ClientError {
fn from(e: CryptoStoreError) -> Self {
anyhow::Error::from(e).into()
}
}
impl From<HttpError> for ClientError {
fn from(e: HttpError) -> Self {
anyhow::Error::from(e).into()
}
}
impl From<IdParseError> for ClientError {
fn from(e: IdParseError) -> Self {
anyhow::Error::from(e).into()
}
}
impl From<serde_json::Error> for ClientError {
fn from(e: serde_json::Error) -> Self {
anyhow::Error::from(e).into()
}
}

View File

@@ -25,6 +25,7 @@ mod platform;
pub mod authentication_service;
pub mod client;
pub mod client_builder;
mod error;
mod helpers;
pub mod notification_service;
pub mod room;
@@ -34,12 +35,12 @@ pub mod sliding_sync;
pub mod timeline;
pub mod tracing;
use client::Client;
use client_builder::ClientBuilder;
use matrix_sdk::{encryption::CryptoStoreError, HttpError, IdParseError};
use once_cell::sync::Lazy;
use tokio::runtime::Runtime;
// Re-exports for more convenient use inside other submodules
use self::{client::Client, client_builder::ClientBuilder, error::ClientError};
pub static RUNTIME: Lazy<Runtime> =
Lazy::new(|| Runtime::new().expect("Can't start Tokio runtime"));
@@ -47,54 +48,11 @@ pub use matrix_sdk::{
room::timeline::PaginationOutcome,
ruma::{api::client::account::register, UserId},
};
pub use platform::*;
pub use self::{
authentication_service::*, client::*, notification_service::*, room::*, room_member::*,
session_verification::*, sliding_sync::*, timeline::*, tracing::*,
};
#[derive(thiserror::Error, Debug)]
pub enum ClientError {
#[error("client error: {msg}")]
Generic { msg: String },
}
impl From<anyhow::Error> for ClientError {
fn from(e: anyhow::Error) -> ClientError {
ClientError::Generic { msg: e.to_string() }
}
}
impl From<matrix_sdk::Error> for ClientError {
fn from(e: matrix_sdk::Error) -> Self {
anyhow::Error::from(e).into()
}
}
impl From<CryptoStoreError> for ClientError {
fn from(e: CryptoStoreError) -> Self {
anyhow::Error::from(e).into()
}
}
impl From<HttpError> for ClientError {
fn from(e: HttpError) -> Self {
anyhow::Error::from(e).into()
}
}
impl From<IdParseError> for ClientError {
fn from(e: IdParseError) -> Self {
anyhow::Error::from(e).into()
}
}
impl From<serde_json::Error> for ClientError {
fn from(e: serde_json::Error) -> Self {
anyhow::Error::from(e).into()
}
}
pub use platform::*;
uniffi::include_scaffolding!("api");