workflow_dom/
error.rs

1//!
2//! Errors return by the [`workflow_dom`](super) module
3//!
4use thiserror::Error;
5use wasm_bindgen::JsValue;
6use workflow_core::channel::RecvError;
7// use workflow_core::sendable::Sendable;
8use workflow_wasm::jserror::*;
9
10/// Errors return by the [`workflow_dom`](super) module
11#[derive(Error, Debug, Clone)]
12pub enum Error {
13    /// Custom string error
14    #[error("{0}")]
15    String(String),
16    /// Error containing [`wasm_bindgen::JsValue`] value
17    // #[error("{0:?}")]
18    // JsValue(Sendable<JsValue>),
19    #[error("{0}")]
20    JsValue(JsErrorData),
21    #[error("{0}")]
22    RecvError(RecvError), //#[from] workflow_core::channel::RecvError),
23}
24
25unsafe impl Send for Error {}
26unsafe impl Sync for Error {}
27
28impl From<String> for Error {
29    fn from(v: String) -> Self {
30        Self::String(v)
31    }
32}
33
34impl From<&str> for Error {
35    fn from(v: &str) -> Self {
36        Self::String(v.to_string())
37    }
38}
39
40impl From<JsValue> for Error {
41    fn from(error: JsValue) -> Self {
42        Self::JsValue(error.into())
43    }
44}
45
46impl From<RecvError> for Error {
47    fn from(err: RecvError) -> Self {
48        Self::RecvError(err)
49    }
50}
51
52impl From<Error> for JsValue {
53    fn from(err: Error) -> Self {
54        JsValue::from_str(&err.to_string())
55    }
56}