feat(updater): refactor and improvements (#431)

Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
Co-authored-by: Lucas Nogueira <lucas@tauri.app>
This commit is contained in:
Amr Bashir
2023-08-07 22:01:21 +03:00
committed by GitHub
parent 84133b57b8
commit 4ab90f048e
18 changed files with 1231 additions and 2728 deletions
+42 -64
View File
@@ -2,92 +2,68 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
use http::StatusCode;
use serde::{Serialize, Serializer};
use thiserror::Error;
/// All errors that can occur while running the updater.
#[derive(Debug, thiserror::Error)]
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum Error {
/// IO Errors.
#[error("`{0}`")]
Io(#[from] std::io::Error),
/// Semver Errors.
#[error("Unable to compare version: {0}")]
Semver(#[from] semver::Error),
/// JSON (Serde) Errors.
#[error("JSON error: {0}")]
SerdeJson(#[from] serde_json::Error),
/// Minisign is used for signature validation.
#[error("Verify signature error: {0}")]
Minisign(#[from] minisign_verify::Error),
/// Error with Minisign base64 decoding.
#[error("Signature decoding error: {0}")]
Base64(#[from] base64::DecodeError),
/// UTF8 Errors in signature.
#[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),
/// Tauri utils, mainly extract and file move.
#[error("Tauri API error: {0}")]
TauriApi(#[from] tauri::api::Error),
/// Network error.
#[error("Download request failed with status: {0}")]
DownloadFailed(StatusCode),
/// Network error.
#[error("Network error: {0}")]
Network(#[from] reqwest::Error),
/// Failed to serialize header value as string.
/// Endpoints are not sent.
#[error("Updater does not have any endpoints set.")]
EmptyEndpoints,
/// IO errors.
#[error(transparent)]
Utf8(#[from] std::string::FromUtf8Error),
Io(#[from] std::io::Error),
/// Semver errors.
#[error(transparent)]
Semver(#[from] semver::Error),
/// Serialization errors.
#[error(transparent)]
Serialization(#[from] serde_json::Error),
/// Could not fetch a valid response from the server.
#[error("Could not fetch a valid release JSON from the remote")]
ReleaseNotFound,
/// Error building updater.
#[error("Unable to prepare the updater: {0}")]
Builder(String),
/// Error building updater.
#[error("Unable to extract the new version: {0}")]
Extract(String),
/// Updater cannot be executed on this Linux package. Currently the updater is enabled only on AppImages.
#[error(
"Cannot run updater on this Linux package. Currently only an AppImage can be updated."
)]
UnsupportedLinuxPackage,
/// Operating system is not supported.
#[error("unsupported OS, expected one of `linux`, `darwin` or `windows`.")]
UnsupportedOs,
/// Unsupported app architecture.
#[error(
"Unsupported application architecture, expected one of `x86`, `x86_64`, `arm` or `aarch64`."
)]
UnsupportedArch,
/// Operating system is not supported.
#[error("Unsupported OS, expected one of `linux`, `darwin` or `windows`.")]
UnsupportedOs,
/// Failed to determine updater package extract path
#[error("Failed to determine updater package extract path.")]
FailedToDetermineExtractPath,
/// Url parsing errors.
#[error(transparent)]
UrlParse(#[from] url::ParseError),
/// `reqwest` crate errors.
#[error(transparent)]
Reqwest(#[from] reqwest::Error),
/// The platform was not found on the updater JSON response.
#[error("the platform `{0}` was not found on the response `platforms` object")]
TargetNotFound(String),
/// Triggered when there is NO error and the two versions are equals.
/// On client side, it's important to catch this error.
#[error("No updates available")]
UpToDate,
/// The updater responded with an invalid signature type.
#[error("the updater response field `{0}` type is invalid, expected {1} but found {2}")]
InvalidResponseType(&'static str, &'static str, serde_json::Value),
/// HTTP error.
/// Download failed
#[error("`{0}`")]
Network(String),
/// `minisign_verify` errors.
#[error(transparent)]
Http(#[from] http::Error),
Minisign(#[from] minisign_verify::Error),
/// `base64` errors.
#[error(transparent)]
Base64(#[from] base64::DecodeError),
/// UTF8 Errors in signature.
#[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),
/// `zip` errors.
#[error(transparent)]
Extract(#[from] zip::result::ZipError),
/// Temp dir is not on same mount mount. This prevents our updater to rename the AppImage to a temp file.
#[cfg(target_os = "linux")]
#[error("temp directory is not on the same mount point as the AppImage")]
TempDirNotOnSameMountPoint,
/// The path StripPrefixError error.
#[error("Path Error: {0}")]
PathPrefix(#[from] std::path::StripPrefixError),
/// Ignore error.
#[error("failed to walkdir: {0}")]
Ignore(#[from] ignore::Error),
/// Zip error.
#[cfg(windows)]
#[error(transparent)]
ZipError(#[from] zip::result::ZipError),
Http(#[from] http::Error),
}
impl Serialize for Error {
@@ -98,3 +74,5 @@ impl Serialize for Error {
serializer.serialize_str(self.to_string().as_ref())
}
}
pub type Result<T> = std::result::Result<T, Error>;