tauri_plugin_updater/
error.rs

1// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
2// SPDX-License-Identifier: Apache-2.0
3// SPDX-License-Identifier: MIT
4
5use serde::{Serialize, Serializer};
6use thiserror::Error;
7
8/// All errors that can occur while running the updater.
9#[derive(Debug, Error)]
10#[non_exhaustive]
11pub enum Error {
12    /// Endpoints are not sent.
13    #[error("Updater does not have any endpoints set.")]
14    EmptyEndpoints,
15    /// IO errors.
16    #[error(transparent)]
17    Io(#[from] std::io::Error),
18    /// Semver errors.
19    #[error(transparent)]
20    Semver(#[from] semver::Error),
21    /// Serialization errors.
22    #[error(transparent)]
23    Serialization(#[from] serde_json::Error),
24    /// Could not fetch a valid response from the server.
25    #[error("Could not fetch a valid release JSON from the remote")]
26    ReleaseNotFound,
27    /// Unsupported app architecture.
28    #[error("Unsupported application architecture, expected one of `x86`, `x86_64`, `arm` or `aarch64`.")]
29    UnsupportedArch,
30    /// Operating system is not supported.
31    #[error("Unsupported OS, expected one of `linux`, `darwin` or `windows`.")]
32    UnsupportedOs,
33    /// Failed to determine updater package extract path
34    #[error("Failed to determine updater package extract path.")]
35    FailedToDetermineExtractPath,
36    /// Url parsing errors.
37    #[error(transparent)]
38    UrlParse(#[from] url::ParseError),
39    /// `reqwest` crate errors.
40    #[error(transparent)]
41    Reqwest(#[from] reqwest::Error),
42    /// The platform was not found on the updater JSON response.
43    #[error("the platform `{0}` was not found on the response `platforms` object")]
44    TargetNotFound(String),
45    /// Download failed
46    #[error("`{0}`")]
47    Network(String),
48    /// `minisign_verify` errors.
49    #[error(transparent)]
50    Minisign(#[from] minisign_verify::Error),
51    /// `base64` errors.
52    #[error(transparent)]
53    Base64(#[from] base64::DecodeError),
54    /// UTF8 Errors in signature.
55    #[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.")]
56    SignatureUtf8(String),
57    #[cfg(all(target_os = "windows", feature = "zip"))]
58    /// `zip` errors.
59    #[error(transparent)]
60    Extract(#[from] zip::result::ZipError),
61    /// Temp dir is not on same mount mount. This prevents our updater to rename the AppImage to a temp file.
62    #[error("temp directory is not on the same mount point as the AppImage")]
63    TempDirNotOnSameMountPoint,
64    #[error("binary for the current target not found in the archive")]
65    BinaryNotFoundInArchive,
66    #[error("failed to create temporary directory")]
67    TempDirNotFound,
68    #[error("Authentication failed or was cancelled")]
69    AuthenticationFailed,
70    #[error("Failed to install .deb package")]
71    DebInstallFailed,
72    #[error("invalid updater binary format")]
73    InvalidUpdaterFormat,
74    #[error(transparent)]
75    Http(#[from] http::Error),
76    #[error(transparent)]
77    InvalidHeaderValue(#[from] http::header::InvalidHeaderValue),
78    #[error(transparent)]
79    InvalidHeaderName(#[from] http::header::InvalidHeaderName),
80    #[error("Failed to format date")]
81    FormatDate,
82    /// The configured updater endpoint must use a secure protocol like `https`
83    #[error("The configured updater endpoint must use a secure protocol like `https`.")]
84    InsecureTransportProtocol,
85    #[error(transparent)]
86    Tauri(#[from] tauri::Error),
87}
88
89impl Serialize for Error {
90    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
91    where
92        S: Serializer,
93    {
94        serializer.serialize_str(self.to_string().as_ref())
95    }
96}
97
98pub type Result<T> = std::result::Result<T, Error>;