1use serde::{Deserialize, Serialize};
2
3#[cfg(feature = "client")]
4#[derive(Debug, thiserror::Error)]
5pub enum ClientError {
6 #[error("client failed: {0}")]
7 ClientFailed(#[from] anyhow::Error),
8 #[error("RPC failed: {0}")]
9 RpcFailed(#[from] tarpc::client::RpcError),
10 #[error("server responded with an error: {0}")]
11 Internal(#[from] ServerError),
12}
13
14#[cfg(feature = "client")]
15pub type ClientResult<T, E = ClientError> = std::result::Result<T, E>;
16
17#[derive(Debug, thiserror::Error, Serialize, Deserialize)]
18#[error("server error: {0}")]
19pub struct ServerError(String);
20
21impl ServerError {
22 pub fn new<S: Into<String>>(msg: S) -> Self {
23 Self(msg.into())
24 }
25}
26
27impl From<anyhow::Error> for ServerError {
28 fn from(value: anyhow::Error) -> Self {
29 Self(value.to_string())
30 }
31}
32
33impl From<tycho_types::error::Error> for ServerError {
34 fn from(value: tycho_types::error::Error) -> Self {
35 Self(value.to_string())
36 }
37}
38
39pub type ServerResult<T, E = ServerError> = std::result::Result<T, E>;