kaspa_wrpc_client/
error.rs1use thiserror::Error;
4use wasm_bindgen::JsError;
5use wasm_bindgen::JsValue;
6use workflow_core::channel::ChannelError;
7use workflow_core::sendable::*;
8use workflow_http::error::Error as HttpError;
9use workflow_rpc::client::error::Error as RpcError;
10use workflow_rpc::client::error::WebSocketError;
11use workflow_wasm::error::Error as WasmError;
12use workflow_wasm::printable::*;
13
14#[derive(Debug, Error)]
15pub enum Error {
16 #[error("{0}")]
17 Custom(String),
18
19 #[error("wRPC address error -> {0}")]
20 UrlError(String),
21
22 #[error("wRPC -> {0}")]
23 RpcError(#[from] RpcError),
24
25 #[error("Kaspa RpcApi -> {0}")]
26 RpcApiError(#[from] kaspa_rpc_core::error::RpcError),
27
28 #[error("Kaspa RpcApi -> {0}")]
29 WebSocketError(#[from] WebSocketError),
30
31 #[error("Notification subsystem -> {0}")]
32 NotificationError(#[from] kaspa_notify::error::Error),
33
34 #[error("Channel -> {0}")]
35 ChannelError(String),
36
37 #[error("Serde WASM bindgen serialization or deserialization error: {0}")]
38 SerdeWasmBindgen(Sendable<Printable>),
39
40 #[error("{0}")]
41 JsValue(Sendable<Printable>),
42
43 #[error("{0}")]
44 ToValue(String),
45
46 #[error("invalid network type: {0}")]
47 NetworkType(#[from] kaspa_consensus_core::network::NetworkTypeError),
48
49 #[error(transparent)]
50 ConsensusWasm(#[from] kaspa_consensus_wasm::error::Error),
51
52 #[error(transparent)]
53 HttpError(#[from] HttpError),
54
55 #[error(transparent)]
56 WasmError(#[from] WasmError),
57
58 #[error(transparent)]
59 AddressError(#[from] kaspa_addresses::AddressError),
60
61 #[error(transparent)]
62 TomlError(#[from] toml::de::Error),
63
64 #[error(transparent)]
65 NetworkId(#[from] kaspa_consensus_core::network::NetworkIdError),
66}
67
68impl Error {
69 pub fn custom<T: std::fmt::Display>(msg: T) -> Self {
70 Error::Custom(msg.to_string())
71 }
72}
73
74impl From<String> for Error {
75 fn from(err: String) -> Self {
76 Self::Custom(err)
77 }
78}
79
80impl From<&str> for Error {
81 fn from(err: &str) -> Self {
82 Self::Custom(err.to_string())
83 }
84}
85
86impl<T> From<ChannelError<T>> for Error {
87 fn from(err: ChannelError<T>) -> Self {
88 Error::ChannelError(err.to_string())
89 }
90}
91
92impl From<serde_wasm_bindgen::Error> for Error {
93 fn from(err: serde_wasm_bindgen::Error) -> Self {
94 Error::SerdeWasmBindgen(Sendable(Printable::new(err.into())))
95 }
96}
97
98impl From<JsValue> for Error {
99 fn from(err: JsValue) -> Self {
100 Error::JsValue(Sendable(Printable::new(err)))
101 }
102}
103
104impl From<JsError> for Error {
105 fn from(err: JsError) -> Self {
106 Error::JsValue(Sendable(Printable::new(err.into())))
107 }
108}
109
110impl From<Error> for JsValue {
111 fn from(value: Error) -> Self {
112 match value {
113 Error::JsValue(err) => err.as_ref().into(),
114 _ => JsValue::from(value.to_string()),
115 }
116 }
117}
118
119