Skip to main content

lightshuttle_runtime/
error.rs

1//! Error type returned by container runtime operations.
2
3use std::time::Duration;
4
5/// Shorthand alias for `std::result::Result<T, RuntimeError>`.
6pub type Result<T> = std::result::Result<T, RuntimeError>;
7
8/// Errors raised by a [`crate::ContainerRuntime`] implementation.
9#[derive(Debug, thiserror::Error)]
10pub enum RuntimeError {
11    /// The runtime could not establish a connection to the underlying
12    /// container daemon (Docker socket, Podman API, ...).
13    #[error("failed to connect to the container runtime")]
14    Connect(#[source] bollard::errors::Error),
15
16    /// Pulling an image from the registry failed.
17    #[error("failed to pull image `{image}`")]
18    ImagePull {
19        /// The image reference that the runtime tried to pull.
20        image: String,
21        /// Underlying error from the container daemon.
22        #[source]
23        source: bollard::errors::Error,
24    },
25
26    /// The runtime refused to start the container.
27    #[error("failed to start container")]
28    Start(#[source] bollard::errors::Error),
29
30    /// The runtime refused to stop a container.
31    #[error("failed to stop container `{id}`")]
32    Stop {
33        /// Identifier of the container that could not be stopped.
34        id: String,
35        /// Underlying error from the container daemon.
36        #[source]
37        source: bollard::errors::Error,
38    },
39
40    /// The runtime refused to remove a container.
41    #[error("failed to remove container `{name}`")]
42    Remove {
43        /// Name of the container that could not be removed.
44        name: String,
45        /// Underlying error from the container daemon.
46        #[source]
47        source: bollard::errors::Error,
48    },
49
50    /// The runtime could not inspect a container.
51    #[error("failed to inspect container `{id}`")]
52    Inspect {
53        /// Identifier of the container that could not be inspected.
54        id: String,
55        /// Underlying error from the container daemon.
56        #[source]
57        source: bollard::errors::Error,
58    },
59
60    /// The container does not exist on the daemon.
61    #[error("container `{0}` not found")]
62    NotFound(String),
63
64    /// A blocking operation exceeded its allotted time budget.
65    #[error("operation `{operation}` timed out after {after:?}")]
66    Timeout {
67        /// Short name of the operation that timed out.
68        operation: &'static str,
69        /// Configured timeout.
70        after: Duration,
71    },
72
73    /// Streaming logs from a container failed mid-flight.
74    #[error("log stream error")]
75    LogStream(#[source] bollard::errors::Error),
76
77    /// Building an image from a Dockerfile failed.
78    #[error("failed to build image from Dockerfile")]
79    Build(#[source] bollard::errors::Error),
80
81    /// The provided [`crate::ContainerSpec`] is structurally invalid.
82    #[error("invalid container spec: {0}")]
83    InvalidSpec(String),
84}