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    /// Snapshot descriptor parsing, validation, or serialization failed.
34    #[error(transparent)]
35    SnapshotManifest(#[from] microsandbox_types::SnapshotManifestError),
36
37    /// OCI image config parsing failed.
38    #[error("config parse error: {0}")]
39    ConfigParse(String),
40
41    /// Layer download hash mismatch (possible corruption or tampering).
42    #[error("digest mismatch for layer {digest}: expected {expected}, got {actual}")]
43    DigestMismatch {
44        /// The layer digest.
45        digest: String,
46        /// Expected hash.
47        expected: String,
48        /// Actual computed hash.
49        actual: String,
50    },
51
52    /// Layer materialization failed.
53    #[error("materialization failed for layer {digest}: {message}")]
54    Materialize {
55        /// The layer digest.
56        digest: String,
57        /// Error detail.
58        message: String,
59        /// The underlying error.
60        #[source]
61        source: Option<Box<dyn std::error::Error + Send + Sync>>,
62    },
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    /// Invalid PEM certificate data.
82    #[error("invalid PEM certificate: {0}")]
83    InvalidCertificate(String),
84
85    /// General I/O error.
86    #[error(transparent)]
87    Io(#[from] std::io::Error),
88}
89
90//--------------------------------------------------------------------------------------------------
91// Type Aliases
92//--------------------------------------------------------------------------------------------------
93
94/// Result type for image operations.
95pub type ImageResult<T> = Result<T, ImageError>;