mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-06 15:04:11 -04:00
ffi: Move error type into its own module
This commit is contained in:
committed by
Jonas Platte
parent
4f316a130f
commit
9ffcb8bc8a
43
bindings/matrix-sdk-ffi/src/error.rs
Normal file
43
bindings/matrix-sdk-ffi/src/error.rs
Normal 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()
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user