1use std::sync::PoisonError;
2use thiserror::Error;
3use wasm_bindgen::JsValue;
4use workflow_core::channel::{RecvError, TrySendError};
5use workflow_core::id::Id;
6
7#[derive(Error, Debug)]
9pub enum Error {
10 #[error("Error: {0}")]
12 Custom(String),
13
14 #[error("Callback Error: {0}")]
16 CallbackError(#[from] workflow_wasm::callback::CallbackError),
17
18 #[error("I/O error: {0}")]
20 IO(#[from] std::io::Error),
21
22 #[error("NW error: {0}")]
24 NW(#[from] nw_sys::error::Error),
25
26 #[error("Error: {0}")]
28 JsValue(String),
29
30 #[error("Poison Error: {0}")]
32 PoisonError(String),
33
34 #[error("Error: `window.global` object not found")]
36 GlobalObjectNotFound,
37
38 #[error("IPC Error: target window `{0}` not found")]
40 IpcTargetNotFound(Id),
41
42 #[error("Serde WASM bindgen ser/deser error: {0}")]
44 SerdeWasmBindgen(#[from] serde_wasm_bindgen::Error),
45
46 #[error("Unknown broadcast message kind")]
48 UnknownBroadcastMessageKind,
49
50 #[error("Error parsing id: {0}")]
52 Id(#[from] workflow_core::id::Error),
53
54 #[error("Malformed Ctl message")]
56 MalformedCtl,
57
58 #[error("IPC channel send error")]
60 ChannelSendError,
61
62 #[error("IPC channel receive error")]
64 ChannelRecvError,
65
66 #[error("Broadcast data is not an object")]
68 BroadcastDataNotObject,
69
70 #[error(transparent)]
72 Wasm(#[from] workflow_wasm::error::Error),
73
74 #[error(transparent)]
76 Ipc(#[from] crate::ipc::error::Error),
77 }
80
81impl From<String> for Error {
82 fn from(v: String) -> Self {
83 Self::Custom(v)
84 }
85}
86
87impl From<&str> for Error {
88 fn from(v: &str) -> Self {
89 Self::Custom(v.to_string())
90 }
91}
92
93impl From<JsValue> for Error {
94 fn from(v: JsValue) -> Self {
95 Self::JsValue(format!("{v:?}"))
96 }
97}
98
99impl<T> From<PoisonError<T>> for Error
100where
101 T: std::fmt::Debug,
102{
103 fn from(err: PoisonError<T>) -> Error {
104 Error::PoisonError(format!("{err:?}"))
105 }
106}
107
108impl From<Error> for JsValue {
109 fn from(err: Error) -> JsValue {
110 let s: String = err.to_string();
111 JsValue::from_str(&s)
112 }
113}
114
115impl<T> From<TrySendError<T>> for Error {
116 fn from(_: TrySendError<T>) -> Self {
117 Error::ChannelSendError
118 }
119}
120
121impl From<RecvError> for Error {
122 fn from(_: RecvError) -> Self {
123 Error::ChannelRecvError
124 }
125}