Skip to main content

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 received while awaiting a value on a channel
22    #[error("{0}")]
23    RecvError(RecvError), //#[from] workflow_core::channel::RecvError),
24}
25
26unsafe impl Send for Error {}
27unsafe impl Sync for Error {}
28
29impl From<String> for Error {
30    fn from(v: String) -> Self {
31        Self::String(v)
32    }
33}
34
35impl From<&str> for Error {
36    fn from(v: &str) -> Self {
37        Self::String(v.to_string())
38    }
39}
40
41impl From<JsValue> for Error {
42    fn from(error: JsValue) -> Self {
43        Self::JsValue(error.into())
44    }
45}
46
47impl From<RecvError> for Error {
48    fn from(err: RecvError) -> Self {
49        Self::RecvError(err)
50    }
51}
52
53impl From<Error> for JsValue {
54    fn from(err: Error) -> Self {
55        JsValue::from_str(&err.to_string())
56    }
57}