microsandbox_image/error.rs
1//! Error types for image operations.
2
3use std::path::PathBuf;
4
5//--------------------------------------------------------------------------------------------------
6// Types
7//--------------------------------------------------------------------------------------------------
8
9/// Errors that can occur during image operations.
10#[derive(Debug, thiserror::Error)]
11pub enum ImageError {
12 /// Network or registry communication error.
13 #[error("registry error: {0}")]
14 Registry(#[from] oci_client::errors::OciDistributionError),
15
16 /// No manifest found matching the requested platform.
17 #[error("no manifest for platform {os}/{arch} in {reference}")]
18 PlatformNotFound {
19 /// The image reference.
20 reference: String,
21 /// Requested OS.
22 os: String,
23 /// Requested architecture.
24 arch: String,
25 },
26
27 /// OCI manifest or index parsing failed.
28 #[error("manifest parse error: {0}")]
29 ManifestParse(String),
30
31 /// OCI image config parsing failed.
32 #[error("config parse error: {0}")]
33 ConfigParse(String),
34
35 /// Layer download hash mismatch (possible corruption or tampering).
36 #[error("digest mismatch for layer {digest}: expected {expected}, got {actual}")]
37 DigestMismatch {
38 /// The layer digest.
39 digest: String,
40 /// Expected hash.
41 expected: String,
42 /// Actual computed hash.
43 actual: String,
44 },
45
46 /// Layer extraction failed.
47 #[error("extraction failed for layer {digest}: {message}")]
48 Extraction {
49 /// The layer digest.
50 digest: String,
51 /// Error detail.
52 message: String,
53 /// The underlying error.
54 #[source]
55 source: Option<Box<dyn std::error::Error + Send + Sync>>,
56 },
57
58 /// Sidecar index generation failed.
59 #[error("index generation failed for layer {0}: {1}")]
60 IndexBuild(String, #[source] std::io::Error),
61
62 /// Cache I/O error.
63 #[error("cache error at {}: {source}", path.display())]
64 Cache {
65 /// The path that caused the error.
66 path: PathBuf,
67 /// The underlying I/O error.
68 #[source]
69 source: std::io::Error,
70 },
71
72 /// Image not found in local cache (PullPolicy::Never).
73 #[error("image not cached: {reference}")]
74 NotCached {
75 /// The image reference.
76 reference: String,
77 },
78
79 /// General I/O error.
80 #[error(transparent)]
81 Io(#[from] std::io::Error),
82}
83
84//--------------------------------------------------------------------------------------------------
85// Type Aliases
86//--------------------------------------------------------------------------------------------------
87
88/// Result type for image operations.
89pub type ImageResult<T> = Result<T, ImageError>;