workflow_rpc/client/
error.rs1use crate::error::ServerError;
6use crate::messages::serde_json::JsonServerError;
7use serde::*;
8use std::fmt::Display;
9use thiserror::Error;
10use wasm_bindgen::JsValue;
11use workflow_core::channel::{RecvError, SendError, TrySendError};
12pub use workflow_websocket::client::error::Error as WebSocketError;
13
14#[derive(Error, Debug)]
15pub enum Error {
16 #[error("Invalid event '{0}'")]
17 InvalidEvent(String),
18
19 #[error("Invalid URL {0}")]
20 InvalidUrl(String),
21
22 #[error(transparent)]
23 RpcError(#[from] crate::error::Error),
24
25 #[error("response handler for id {0} not found")]
26 ResponseHandler(String),
27
28 #[error("WebSocket disconnected")]
29 Disconnect,
30
31 #[error("Missing method in notification message")]
32 NotificationMethod,
33
34 #[error("invalid WebSocket message type for protocol")]
35 WebSocketMessageType,
36
37 #[error("RPC client is missing notification handler")]
38 MissingNotificationHandler,
39
40 #[error("WebSocket -> {0}")]
42 WebSocketError(#[from] WebSocketError),
43 #[error("RPC request timeout")]
45 Timeout,
46 #[error("Receiver ctl failure")]
48 ReceiverCtl,
49 #[error("RPC has no data in success response")]
51 NoDataInSuccessResponse,
52 #[error("RPC has no data in notification")]
53 NoDataInNotificationMessage,
54 #[error("RPC has no data in the error response")]
56 NoDataInErrorResponse,
57 #[error("RPC error deserializing server message data")]
59 ErrorDeserializingServerMessageData(crate::error::Error),
60 #[error("RPC error deserializing response data")]
62 ErrorDeserializingResponseData,
63 #[error("RPC status code {0}")]
65 StatusCode(u32),
66 #[error("RPC response error {0:?}")]
68 RpcCall(ServerError),
69 #[error("RPC borsh serialization error")]
71 BorshSerialize,
72 #[error("RPC borsh deserialization error: {0}")]
74 BorshDeserialize(String),
75 #[error("RPC serde serialization error: {0}")]
77 SerdeSerialize(String), #[error("RPC serde deserialization error: {0}")]
80 SerdeDeserialize(String),
81 #[error("RPC borsh error deserializing response: {0}")]
83 BorshResponseDeserialize(String),
84
85 #[error("RPC: channel receive error")]
86 ChannelRecvError,
87
88 #[error("RPC: channel send error")]
89 ChannelSendError,
90
91 #[error("Utf8 error: {0}")]
92 Utf8Error(#[from] std::str::Utf8Error),
93
94 #[error("SerdeJSON error: {0}")]
95 SerdeJSON(#[from] serde_json::Error),
96
97 #[error(transparent)]
98 Task(#[from] workflow_task::TaskError),
99
100 #[error("{0}")]
101 ServerError(ServerError),
102
103 #[error("{0}")]
104 JsonServerError(JsonServerError),
105 }
108
109impl From<ServerError> for Error {
110 fn from(err: ServerError) -> Self {
111 Error::ServerError(err)
112 }
113}
114
115impl From<Error> for JsValue {
117 fn from(err: Error) -> JsValue {
118 JsValue::from(err.to_string())
119 }
120}
121
122impl From<RecvError> for Error {
123 fn from(_: RecvError) -> Self {
124 Error::ChannelRecvError
125 }
126}
127
128impl<T> From<SendError<T>> for Error {
129 fn from(_: SendError<T>) -> Self {
130 Error::ChannelSendError
131 }
132}
133
134impl<T> From<TrySendError<T>> for Error {
135 fn from(_: TrySendError<T>) -> Self {
136 Error::ChannelSendError
137 }
138}
139
140impl de::Error for Error {
141 fn custom<T: Display>(msg: T) -> Error {
142 Error::SerdeDeserialize(msg.to_string())
143 }
144}
145
146impl ser::Error for Error {
147 fn custom<T: Display>(msg: T) -> Error {
148 Error::SerdeSerialize(msg.to_string())
149 }
150}
151
152impl From<JsonServerError> for Error {
153 fn from(err: JsonServerError) -> Self {
154 Error::JsonServerError(err)
155 }
156}