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 could not inspect a container.
41    #[error("failed to inspect container `{id}`")]
42    Inspect {
43        /// Identifier of the container that could not be inspected.
44        id: String,
45        /// Underlying error from the container daemon.
46        #[source]
47        source: bollard::errors::Error,
48    },
49
50    /// The container does not exist on the daemon.
51    #[error("container `{0}` not found")]
52    NotFound(String),
53
54    /// A blocking operation exceeded its allotted time budget.
55    #[error("operation `{operation}` timed out after {after:?}")]
56    Timeout {
57        /// Short name of the operation that timed out.
58        operation: &'static str,
59        /// Configured timeout.
60        after: Duration,
61    },
62
63    /// Streaming logs from a container failed mid-flight.
64    #[error("log stream error")]
65    LogStream(#[source] bollard::errors::Error),
66
67    /// Building an image from a Dockerfile failed.
68    #[error("failed to build image from Dockerfile")]
69    Build(#[source] bollard::errors::Error),
70
71    /// The provided [`crate::ContainerSpec`] is structurally invalid.
72    #[error("invalid container spec: {0}")]
73    InvalidSpec(String),
74}