1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use std::num::ParseIntError;
use thiserror::Error;
use wasm_bindgen::JsValue;
use workflow_wasm::printable::Printable;

/// Errors return by the [`workflow_d3`](super) module
#[derive(Error, Debug, Clone)]
pub enum Error {
    #[error("{0}")]
    Custom(String),

    #[error(transparent)]
    Dom(#[from] workflow_dom::error::Error),

    #[error("{0}")]
    JsValue(Printable),

    #[error(transparent)]
    CallbackError(#[from] workflow_wasm::callback::CallbackError),

    #[error(transparent)]
    Wasm(#[from] workflow_wasm::error::Error),
}

impl From<Error> for JsValue {
    fn from(err: Error) -> JsValue {
        let s: String = err.to_string();
        JsValue::from_str(&s)
    }
}

impl From<JsValue> for Error {
    fn from(js_value: JsValue) -> Error {
        Error::JsValue(Printable::new(js_value))
    }
}
impl From<String> for Error {
    fn from(err: String) -> Self {
        Self::Custom(err)
    }
}

impl From<&str> for Error {
    fn from(err: &str) -> Self {
        Self::Custom(err.to_string())
    }
}

impl From<ParseIntError> for Error {
    fn from(err: ParseIntError) -> Self {
        Self::Custom(err.to_string())
    }
}