Skip to main content

tauri_plugin_hotswap/
error.rs

1/// Errors returned by the hotswap plugin.
2#[derive(Debug, thiserror::Error)]
3#[non_exhaustive]
4pub enum Error {
5    /// Network request failed (check, download).
6    #[error("network error: {0}")]
7    Network(String),
8
9    /// HTTP response indicated failure.
10    #[error("HTTP {status}: {message}")]
11    Http {
12        /// HTTP status code.
13        status: u16,
14        /// Human-readable error message.
15        message: String,
16    },
17
18    /// Downloaded bundle exceeds the configured maximum size.
19    #[error("bundle too large: {size} bytes exceeds limit of {limit} bytes")]
20    BundleTooLarge {
21        /// Actual size (or Content-Length) in bytes.
22        size: u64,
23        /// Configured maximum in bytes.
24        limit: u64,
25    },
26
27    /// Minisign signature verification failed.
28    #[error("signature verification failed: {0}")]
29    Signature(String),
30
31    /// Archive extraction failed (corrupt archive, path traversal, etc).
32    #[error("extraction failed: {0}")]
33    Extraction(String),
34
35    /// Manifest JSON could not be parsed.
36    #[error("invalid manifest: {0}")]
37    InvalidManifest(String),
38
39    /// Semver parsing or comparison failed.
40    #[error("version error: {0}")]
41    Version(String),
42
43    /// Plugin configuration is missing or invalid.
44    #[error("configuration error: {0}")]
45    Config(String),
46
47    /// No pending update — `check` must be called before `apply`.
48    #[error("no pending update — call check first")]
49    NoPending,
50
51    /// URL scheme is not HTTPS.
52    #[error("insecure URL rejected: {0} (set require_https = false to allow)")]
53    InsecureUrl(String),
54
55    /// Filesystem I/O error.
56    #[error("I/O error: {0}")]
57    Io(#[from] std::io::Error),
58
59    /// Serialization error.
60    #[error("serialization error: {0}")]
61    Serialization(String),
62
63    /// Mutex was poisoned.
64    #[error("internal state error: lock poisoned")]
65    LockPoisoned,
66}
67
68// Tauri commands require serializable errors.
69impl serde::Serialize for Error {
70    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
71    where
72        S: serde::Serializer,
73    {
74        serializer.serialize_str(&self.to_string())
75    }
76}
77
78/// Convenience alias for `Result<T, Error>`.
79pub type Result<T> = std::result::Result<T, Error>;