simplify error handling
This commit is contained in:
parent
e431dc89a8
commit
bd652c956f
8 changed files with 94 additions and 147 deletions
20
src/lib.rs
20
src/lib.rs
|
@ -17,16 +17,28 @@ pub mod window;
|
|||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum Error {
|
||||
#[error(transparent)]
|
||||
Serde(#[from] serde_wasm_bindgen::Error),
|
||||
#[error("{0}")]
|
||||
Serde(String),
|
||||
#[error("Unknown Theme \"{0}\". Expected one of \"light\",\"dark\"")]
|
||||
UnknownTheme(String),
|
||||
#[error("Invalid Url {0}")]
|
||||
InvalidUrl(#[from] url::ParseError),
|
||||
#[error("Invalid Version {0}")]
|
||||
InvalidVersion(#[from] semver::Error),
|
||||
#[error("{0:?}")]
|
||||
Other(JsValue),
|
||||
#[error("{0}")]
|
||||
Other(String),
|
||||
}
|
||||
|
||||
impl From<serde_wasm_bindgen::Error> for Error {
|
||||
fn from(e: serde_wasm_bindgen::Error) -> Self {
|
||||
Self::Serde(format!("{:?}", e))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<JsValue> for Error {
|
||||
fn from(e: JsValue) -> Self {
|
||||
Self::Serde(format!("{:?}", e))
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) type Result<T> = std::result::Result<T, Error>;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue