workflow_d3/
error.rs

1use std::num::ParseIntError;
2use thiserror::Error;
3use wasm_bindgen::JsValue;
4use workflow_wasm::printable::Printable;
5
6/// Errors return by the [`workflow_d3`](super) module
7#[derive(Error, Debug, Clone)]
8pub enum Error {
9    #[error("{0}")]
10    Custom(String),
11
12    #[error(transparent)]
13    Dom(#[from] workflow_dom::error::Error),
14
15    #[error("{0}")]
16    JsValue(Printable),
17
18    #[error(transparent)]
19    CallbackError(#[from] workflow_wasm::callback::CallbackError),
20
21    #[error(transparent)]
22    Wasm(#[from] workflow_wasm::error::Error),
23}
24
25impl From<Error> for JsValue {
26    fn from(err: Error) -> JsValue {
27        let s: String = err.to_string();
28        JsValue::from_str(&s)
29    }
30}
31
32impl From<JsValue> for Error {
33    fn from(js_value: JsValue) -> Error {
34        Error::JsValue(Printable::new(js_value))
35    }
36}
37impl From<String> for Error {
38    fn from(err: String) -> Self {
39        Self::Custom(err)
40    }
41}
42
43impl From<&str> for Error {
44    fn from(err: &str) -> Self {
45        Self::Custom(err.to_string())
46    }
47}
48
49impl From<ParseIntError> for Error {
50    fn from(err: ParseIntError) -> Self {
51        Self::Custom(err.to_string())
52    }
53}