1use base64::DecodeError;
6use thiserror::Error;
7use wasm_bindgen::prelude::*;
8use workflow_wasm::jserror::*;
9
10#[derive(Error, Debug)]
12pub enum Error {
13 #[error("{0}")]
15 Custom(String),
16
17 #[error("I/O error: {0}")]
19 IoError(#[from] std::io::Error),
20
21 #[error("Chrome error: {0}")]
23 ChromeError(#[from] workflow_chrome::error::Error),
24
25 #[error("{0}")]
29 JsValue(JsErrorData),
30
31 #[error("Base64 decode error: {0}")]
33 DecodeError(DecodeError),
34
35 #[error("Not found: {0}")]
37 NotFound(String),
38
39 #[error("Not a text data: {0}")]
41 DataIsNotAString(String),
42
43 #[error("Not a buffer data: {0}")]
45 DataIsNotABuffer(String),
46
47 #[error(transparent)]
49 SerdeJson(#[from] serde_json::Error),
50
51 #[error("invalid path: {0}")]
53 InvalidPath(String),
54
55 #[error("Unable to obtain user home directory")]
57 HomeDir(String),
58
59 #[error("No file metadata")]
61 Metadata,
62
63 #[error(transparent)]
65 FasterHex(#[from] faster_hex::Error),
66
67 #[error("This operation is not supported")]
69 NotSupported,
70}
71
72impl From<Error> for JsValue {
73 fn from(err: Error) -> Self {
74 match err {
75 Error::JsValue(js_err) => js_err.into(),
76 _ => err.into(),
77 }
78 }
79}
80
81impl From<JsValue> for Error {
91 fn from(error: JsValue) -> Error {
92 Error::JsValue(error.into())
93 }
94}
95
96impl From<JsErrorData> for Error {
97 fn from(error: JsErrorData) -> Error {
98 Error::JsValue(error)
99 }
100}
101
102impl From<DecodeError> for Error {
103 fn from(error: DecodeError) -> Error {
104 Error::DecodeError(error)
105 }
106}
107
108impl From<String> for Error {
109 fn from(error: String) -> Error {
110 Error::Custom(error)
111 }
112}
113
114impl Error {
115 pub fn code(&self) -> Option<&str> {
118 match self {
119 Error::JsValue(js_err) => js_err.code().as_deref(),
120 _ => None,
121 }
122 }
123}