use serde::{Serialize, Serializer};
use thiserror::Error;
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum Error {
#[error("Updater does not have any endpoints set.")]
EmptyEndpoints,
#[error(transparent)]
Io(#[from] std::io::Error),
#[error(transparent)]
Semver(#[from] semver::Error),
#[error(transparent)]
Serialization(#[from] serde_json::Error),
#[error("Could not fetch a valid release JSON from the remote")]
ReleaseNotFound,
#[error("Unsupported application architecture, expected one of `x86`, `x86_64`, `arm` or `aarch64`.")]
UnsupportedArch,
#[error("Unsupported OS, expected one of `linux`, `darwin` or `windows`.")]
UnsupportedOs,
#[error("Failed to determine updater package extract path.")]
FailedToDetermineExtractPath,
#[error(transparent)]
UrlParse(#[from] url::ParseError),
#[error(transparent)]
Reqwest(#[from] reqwest::Error),
#[error("the platform `{0}` was not found on the response `platforms` object")]
TargetNotFound(String),
#[error("`{0}`")]
Network(String),
#[error(transparent)]
Minisign(#[from] minisign_verify::Error),
#[error(transparent)]
Base64(#[from] base64::DecodeError),
#[error("The signature {0} could not be decoded, please check if it is a valid base64 string. The signature must be the contents of the `.sig` file generated by the Tauri bundler, as a string.")]
SignatureUtf8(String),
#[cfg(all(target_os = "windows", feature = "zip"))]
#[error(transparent)]
Extract(#[from] zip::result::ZipError),
#[error("temp directory is not on the same mount point as the AppImage")]
TempDirNotOnSameMountPoint,
#[error("binary for the current target not found in the archive")]
BinaryNotFoundInArchive,
#[error("invalid updater binary format")]
InvalidUpdaterFormat,
#[error(transparent)]
Http(#[from] http::Error),
#[error(transparent)]
Tauri(#[from] tauri::Error),
}
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())
}
}
pub type Result<T> = std::result::Result<T, Error>;