simplify error handling

This commit is contained in:
Jonas Kruckenberg 2022-11-13 21:19:00 +01:00
parent e431dc89a8
commit bd652c956f
8 changed files with 94 additions and 147 deletions

View file

@ -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>;