use serde::{ser::Serializer, Serialize};
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error(transparent)]
Io(#[from] std::io::Error),
#[error(transparent)]
Tauri(#[from] tauri::Error),
#[error(transparent)]
Json(#[from] serde_json::Error),
#[error(transparent)]
Http(#[from] hyper::http::Error),
#[error("Remote UI server is already running")]
ServerAlreadyRunning,
#[error("Primary webview window '{0}' not found")]
PrimaryWindowNotFound(String),
#[error("frontend_dist is configured as a remote URL; a local path is required")]
InvalidFrontendDist,
#[error("WebSocket error: {0}")]
WebSocket(String),
#[error("Plugin error: {0}")]
Plugin(String),
}
impl Serialize for Error {
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_str(self.to_string().as_ref())
}
}
impl From<Error> for tauri::Error {
fn from(err: Error) -> Self {
match err {
Error::Tauri(e) => e,
other => tauri::Error::PluginInitialization(
"tauri-remote-ui".to_owned(),
other.to_string(),
),
}
}
}