Skip to main content

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 in the updater JSON response.
43    #[error("the platform `{0}` was not found in the response `platforms` object")]
44    TargetNotFound(String),
45    /// Neither the platform nor the fallback platform was found in the updater JSON response.
46    #[error(
47        "None of the fallback platforms `{0:?}` were found in the response `platforms` object"
48    )]
49    TargetsNotFound(Vec<String>),
50    /// Download failed
51    #[error("`{0}`")]
52    Network(String),
53    /// `minisign_verify` errors.
54    #[error(transparent)]
55    Minisign(#[from] minisign_verify::Error),
56    /// `base64` errors.
57    #[error(transparent)]
58    Base64(#[from] base64::DecodeError),
59    /// UTF8 Errors in signature.
60    #[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.")]
61    SignatureUtf8(String),
62    #[cfg(all(target_os = "windows", feature = "zip"))]
63    /// `zip` errors.
64    #[error(transparent)]
65    Extract(#[from] zip::result::ZipError),
66    /// Temp dir is not on same mount mount. This prevents our updater to rename the AppImage to a temp file.
67    #[error("temp directory is not on the same mount point as the AppImage")]
68    TempDirNotOnSameMountPoint,
69    #[error("binary for the current target not found in the archive")]
70    BinaryNotFoundInArchive,
71    #[error("failed to create temporary directory")]
72    TempDirNotFound,
73    #[error("Authentication failed or was cancelled")]
74    AuthenticationFailed,
75    #[error("Failed to install .deb package")]
76    DebInstallFailed,
77    #[error("Failed to install package")]
78    PackageInstallFailed,
79    #[error("invalid updater binary format")]
80    InvalidUpdaterFormat,
81    #[error(transparent)]
82    Http(#[from] http::Error),
83    #[error(transparent)]
84    InvalidHeaderValue(#[from] http::header::InvalidHeaderValue),
85    #[error(transparent)]
86    InvalidHeaderName(#[from] http::header::InvalidHeaderName),
87    #[error("Failed to format date")]
88    FormatDate,
89    /// The configured updater endpoint must use a secure protocol like `https`
90    #[error("The configured updater endpoint must use a secure protocol like `https`.")]
91    InsecureTransportProtocol,
92    #[error(transparent)]
93    Tauri(#[from] tauri::Error),
94}
95
96impl Serialize for Error {
97    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
98    where
99        S: Serializer,
100    {
101        serializer.serialize_str(self.to_string().as_ref())
102    }
103}
104
105pub type Result<T> = std::result::Result<T, Error>;