Skip to main content

hdiff_update_core/
error.rs

1use std::{path::PathBuf, process::ExitStatus};
2
3use thiserror::Error;
4
5#[derive(Debug, Error)]
6pub enum Error {
7    #[error("I/O error at {path}: {source}")]
8    IoWithPath {
9        path: PathBuf,
10        #[source]
11        source: std::io::Error,
12    },
13    #[error("I/O error: {0}")]
14    Io(#[from] std::io::Error),
15    #[error("HTTP error: {0}")]
16    Http(#[from] reqwest::Error),
17    #[error("URL error: {0}")]
18    Url(#[from] url::ParseError),
19    #[error("JSON error: {0}")]
20    Json(#[from] serde_json::Error),
21    #[error("tool not found: {tool}")]
22    ToolNotFound { tool: String },
23    #[error("process failed: {program} {args:?}, status={status}, stderr={stderr}")]
24    ProcessFailed {
25        program: PathBuf,
26        args: Vec<String>,
27        status: ExitStatus,
28        stdout: String,
29        stderr: String,
30    },
31    #[error("SHA-256 mismatch for {path}: expected {expected}, got {actual}")]
32    HashMismatch {
33        path: PathBuf,
34        expected: String,
35        actual: String,
36    },
37    #[error("size mismatch for {path}: expected {expected}, got {actual}")]
38    SizeMismatch {
39        path: PathBuf,
40        expected: u64,
41        actual: u64,
42    },
43    #[error("update manifest signature is required but missing")]
44    SignatureMissing,
45    #[error("update manifest signature public key is required")]
46    SignaturePublicKeyMissing,
47    #[error("update manifest signature verification failed")]
48    SignatureVerificationFailed,
49    #[error("invalid {kind}: {message}")]
50    InvalidKeyMaterial { kind: String, message: String },
51    #[error("unsupported patch algorithm: {0}")]
52    UnsupportedAlgorithm(String),
53    #[error("unexpected update version: expected {expected}, got {actual}")]
54    UnexpectedVersion { expected: String, actual: String },
55    #[error("manifest has no platform entry for {platform}")]
56    MissingPlatform { platform: String },
57    #[error("no matching update artifact for platform={platform}, current_version={current_version:?}, current_sha256={current_sha256:?}")]
58    NoMatchingArtifact {
59        platform: String,
60        current_version: Option<String>,
61        current_sha256: Option<String>,
62    },
63    #[error("unsupported URL or path: {0}")]
64    UnsupportedUrl(String),
65    #[error("{0}")]
66    Message(String),
67}
68
69pub type Result<T> = std::result::Result<T, Error>;
70
71pub(crate) fn io_path(path: impl Into<PathBuf>, source: std::io::Error) -> Error {
72    Error::IoWithPath {
73        path: path.into(),
74        source,
75    }
76}