millennium 1.0.0-beta.3

Create consistent, light, & secure apps that work on all platforms, using HTML, CSS, and JavaScript
Documentation
// Copyright 2022 pyke.io
//           2019-2021 Tauri Programme within The Commons Conservancy
//                     [https://tauri.studio/]
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use thiserror::Error;

/// All errors that can occur while running the updater.
#[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; check if it's a valid Base64 string. The signature must be the contents of the `.sig` file generated by the Millennium bundler, as a string."
	)]
	SignatureUtf8(String),
	/// Millennium utils, mainly extract and file move.
	#[error("Millennium API error: {0}")]
	MillenniumApi(#[from] crate::api::Error),
	/// Network error.
	#[error("Network error: {0}")]
	Network(String),
	/// Could not fetch a valid response from the server.
	#[error("Could not fetch a valid release JSON from the remote update server.")]
	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,
	/// The platform was not found in the updater JSON response.
	#[error("The platform `{0}` was not found in the update 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}` has an invalid type; expected {1}, but found {2}.")]
	InvalidResponseType(&'static str, &'static str, serde_json::Value),
	/// HTTP error.
	#[error(transparent)]
	Http(#[from] http::Error)
}

pub type Result<T = ()> = std::result::Result<T, Error>;