Skip to main content

microsandbox_image/
error.rs

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