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)]
16pub enum Error {
17 #[error("Invalid event '{0}'")]
19 InvalidEvent(String),
20
21 #[error("Invalid URL {0}")]
23 InvalidUrl(String),
24
25 #[error(transparent)]
27 RpcError(#[from] crate::error::Error),
28
29 #[error("response handler for id {0} not found")]
31 ResponseHandler(String),
32
33 #[error("WebSocket disconnected")]
35 Disconnect,
36
37 #[error("Missing method in notification message")]
39 NotificationMethod,
40
41 #[error("invalid WebSocket message type for protocol")]
43 WebSocketMessageType,
44
45 #[error("RPC client is missing notification handler")]
47 MissingNotificationHandler,
48
49 #[error("WebSocket -> {0}")]
51 WebSocketError(#[from] WebSocketError),
52 #[error("RPC request timeout")]
54 Timeout,
55 #[error("Receiver ctl failure")]
57 ReceiverCtl,
58 #[error("RPC has no data in success response")]
60 NoDataInSuccessResponse,
61 #[error("RPC has no data in notification")]
63 NoDataInNotificationMessage,
64 #[error("RPC has no data in the error response")]
66 NoDataInErrorResponse,
67 #[error("RPC error deserializing server message data")]
69 ErrorDeserializingServerMessageData(crate::error::Error),
70 #[error("RPC error deserializing response data")]
72 ErrorDeserializingResponseData,
73 #[error("RPC status code {0}")]
75 StatusCode(u32),
76 #[error("RPC response error {0:?}")]
78 RpcCall(ServerError),
79 #[error("RPC borsh serialization error")]
81 BorshSerialize,
82 #[error("RPC borsh deserialization error: {0}")]
84 BorshDeserialize(String),
85 #[error("RPC serde serialization error: {0}")]
87 SerdeSerialize(String), #[error("RPC serde deserialization error: {0}")]
90 SerdeDeserialize(String),
91 #[error("RPC borsh error deserializing response: {0}")]
93 BorshResponseDeserialize(String),
94
95 #[error("RPC: channel receive error")]
97 ChannelRecvError,
98
99 #[error("RPC: channel send error")]
101 ChannelSendError,
102
103 #[error("Utf8 error: {0}")]
105 Utf8Error(#[from] std::str::Utf8Error),
106
107 #[error("SerdeJSON error: {0}")]
109 SerdeJSON(#[from] serde_json::Error),
110
111 #[error(transparent)]
113 Task(#[from] workflow_task::TaskError),
114
115 #[error("{0}")]
117 ServerError(ServerError),
118
119 #[error("{0}")]
121 JsonServerError(JsonServerError),
122 }
125
126impl From<ServerError> for Error {
127 fn from(err: ServerError) -> Self {
128 Error::ServerError(err)
129 }
130}
131
132impl From<Error> for JsValue {
134 fn from(err: Error) -> JsValue {
135 JsValue::from(err.to_string())
136 }
137}
138
139impl From<RecvError> for Error {
140 fn from(_: RecvError) -> Self {
141 Error::ChannelRecvError
142 }
143}
144
145impl<T> From<SendError<T>> for Error {
146 fn from(_: SendError<T>) -> Self {
147 Error::ChannelSendError
148 }
149}
150
151impl<T> From<TrySendError<T>> for Error {
152 fn from(_: TrySendError<T>) -> Self {
153 Error::ChannelSendError
154 }
155}
156
157impl de::Error for Error {
158 fn custom<T: Display>(msg: T) -> Error {
159 Error::SerdeDeserialize(msg.to_string())
160 }
161}
162
163impl ser::Error for Error {
164 fn custom<T: Display>(msg: T) -> Error {
165 Error::SerdeSerialize(msg.to_string())
166 }
167}
168
169impl From<JsonServerError> for Error {
170 fn from(err: JsonServerError) -> Self {
171 Error::JsonServerError(err)
172 }
173}