Skip to main content

arcbox_oci/
error.rs

1//! Error types for OCI operations.
2
3use std::path::PathBuf;
4
5use arcbox_error::CommonError;
6use thiserror::Error;
7
8/// Result type alias for OCI operations.
9pub type Result<T> = std::result::Result<T, OciError>;
10
11/// Errors that can occur during OCI operations.
12#[derive(Debug, Error)]
13pub enum OciError {
14    /// Common errors shared across `ArcBox` crates.
15    #[error(transparent)]
16    Common(#[from] CommonError),
17
18    /// Invalid OCI version.
19    #[error("invalid OCI version: {0}")]
20    InvalidVersion(String),
21
22    /// Missing required field.
23    #[error("missing required field: {0}")]
24    MissingField(&'static str),
25
26    /// Invalid configuration.
27    #[error("invalid configuration: {0}")]
28    InvalidConfig(String),
29
30    /// Bundle not found.
31    #[error("bundle not found: {0}")]
32    BundleNotFound(PathBuf),
33
34    /// Config file not found in bundle.
35    #[error("config.json not found in bundle: {0}")]
36    ConfigNotFound(PathBuf),
37
38    /// Invalid bundle structure.
39    #[error("invalid bundle structure: {0}")]
40    InvalidBundle(String),
41
42    /// Container not found.
43    #[error("container not found: {0}")]
44    ContainerNotFound(String),
45
46    /// Hook execution failed.
47    #[error("hook execution failed: {path} - {reason}")]
48    HookFailed { path: PathBuf, reason: String },
49
50    /// Hook timeout.
51    #[error("hook timeout: {path} (timeout: {timeout}s)")]
52    HookTimeout { path: PathBuf, timeout: u32 },
53
54    /// Invalid path.
55    #[error("invalid path: {0}")]
56    InvalidPath(String),
57
58    /// JSON parsing error.
59    #[error("JSON error: {0}")]
60    Json(#[from] serde_json::Error),
61}
62
63impl From<std::io::Error> for OciError {
64    fn from(err: std::io::Error) -> Self {
65        Self::Common(CommonError::from(err))
66    }
67}