Skip to main content

sal_virt/nerdctl/
mod.rs

1mod cmd;
2mod container;
3mod container_builder;
4mod container_functions;
5mod container_operations;
6#[cfg(test)]
7mod container_test;
8mod container_types;
9mod health_check;
10mod health_check_script;
11mod images;
12
13use std::error::Error;
14use std::fmt;
15use std::io;
16
17/// Error type for nerdctl operations
18#[derive(Debug)]
19pub enum NerdctlError {
20    /// The nerdctl command failed to execute
21    CommandExecutionFailed(io::Error),
22    /// The nerdctl command executed but returned an error
23    CommandFailed(String),
24    /// Failed to parse JSON output
25    JsonParseError(String),
26    /// Failed to convert data
27    ConversionError(String),
28    /// Generic error
29    Other(String),
30}
31
32impl fmt::Display for NerdctlError {
33    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
34        match self {
35            NerdctlError::CommandExecutionFailed(e) => {
36                write!(f, "Failed to execute nerdctl command: {}", e)
37            }
38            NerdctlError::CommandFailed(e) => write!(f, "Nerdctl command failed: {}", e),
39            NerdctlError::JsonParseError(e) => write!(f, "Failed to parse JSON: {}", e),
40            NerdctlError::ConversionError(e) => write!(f, "Conversion error: {}", e),
41            NerdctlError::Other(e) => write!(f, "{}", e),
42        }
43    }
44}
45
46impl Error for NerdctlError {
47    fn source(&self) -> Option<&(dyn Error + 'static)> {
48        match self {
49            NerdctlError::CommandExecutionFailed(e) => Some(e),
50            _ => None,
51        }
52    }
53}
54
55pub use cmd::*;
56pub use container_functions::*;
57pub use container_types::{Container, ContainerStatus, HealthCheck, ResourceUsage};
58pub use health_check_script::*;
59pub use images::*;