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)]
8pub enum Error {
9 #[error("Error: {0}")]
10 Custom(String),
11
12 #[error("Callback Error: {0}")]
13 CallbackError(#[from] workflow_wasm::callback::CallbackError),
14
15 #[error("I/O error: {0}")]
16 IO(#[from] std::io::Error),
17
18 #[error("NW error: {0}")]
19 NW(#[from] nw_sys::error::Error),
20
21 #[error("Error: {0}")]
22 JsValue(String),
23
24 #[error("Poison Error: {0}")]
25 PoisonError(String),
26
27 #[error("Error: `window.global` object not found")]
28 GlobalObjectNotFound,
29
30 #[error("IPC Error: target window `{0}` not found")]
31 IpcTargetNotFound(Id),
32
33 #[error("Serde WASM bindgen ser/deser error: {0}")]
34 SerdeWasmBindgen(#[from] serde_wasm_bindgen::Error),
35
36 #[error("Unknown broadcast message kind")]
37 UnknownBroadcastMessageKind,
38
39 #[error("Error parsing id: {0}")]
40 Id(#[from] workflow_core::id::Error),
41
42 #[error("Malformed Ctl message")]
43 MalformedCtl,
44
45 #[error("IPC channel send error")]
46 ChannelSendError,
47
48 #[error("IPC channel receive error")]
49 ChannelRecvError,
50
51 #[error("Broadcast data is not an object")]
52 BroadcastDataNotObject,
53
54 #[error(transparent)]
55 Wasm(#[from] workflow_wasm::error::Error),
56
57 #[error(transparent)]
58 Ipc(#[from] crate::ipc::error::Error),
59 }
62
63impl From<String> for Error {
64 fn from(v: String) -> Self {
65 Self::Custom(v)
66 }
67}
68
69impl From<&str> for Error {
70 fn from(v: &str) -> Self {
71 Self::Custom(v.to_string())
72 }
73}
74
75impl From<JsValue> for Error {
76 fn from(v: JsValue) -> Self {
77 Self::JsValue(format!("{v:?}"))
78 }
79}
80
81impl<T> From<PoisonError<T>> for Error
82where
83 T: std::fmt::Debug,
84{
85 fn from(err: PoisonError<T>) -> Error {
86 Error::PoisonError(format!("{err:?}"))
87 }
88}
89
90impl From<Error> for JsValue {
91 fn from(err: Error) -> JsValue {
92 let s: String = err.to_string();
93 JsValue::from_str(&s)
94 }
95}
96
97impl<T> From<TrySendError<T>> for Error {
98 fn from(_: TrySendError<T>) -> Self {
99 Error::ChannelSendError
100 }
101}
102
103impl From<RecvError> for Error {
104 fn from(_: RecvError) -> Self {
105 Error::ChannelRecvError
106 }
107}