hdiff_update_core/
error.rs1use 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("manifest has no platform entry for {platform}")]
54 MissingPlatform { platform: String },
55 #[error("no matching update artifact for platform={platform}, current_version={current_version:?}, current_sha256={current_sha256:?}")]
56 NoMatchingArtifact {
57 platform: String,
58 current_version: Option<String>,
59 current_sha256: Option<String>,
60 },
61 #[error("unsupported URL or path: {0}")]
62 UnsupportedUrl(String),
63 #[error("{0}")]
64 Message(String),
65}
66
67pub type Result<T> = std::result::Result<T, Error>;
68
69pub(crate) fn io_path(path: impl Into<PathBuf>, source: std::io::Error) -> Error {
70 Error::IoWithPath {
71 path: path.into(),
72 source,
73 }
74}