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 /// Creating the per-project Docker bridge network failed.
78 #[error("failed to create network `{name}`")]
79 NetworkCreate {
80 /// Name of the network that could not be created.
81 name: String,
82 /// Underlying error from the container daemon.
83 #[source]
84 source: bollard::errors::Error,
85 },
86
87 /// Removing the per-project Docker bridge network failed.
88 #[error("failed to remove network `{name}`")]
89 NetworkRemove {
90 /// Name of the network that could not be removed.
91 name: String,
92 /// Underlying error from the container daemon.
93 #[source]
94 source: bollard::errors::Error,
95 },
96
97 /// Building an image from a Dockerfile failed.
98 #[error("failed to build image from Dockerfile")]
99 Build(#[source] bollard::errors::Error),
100
101 /// The `BuildKit` builder reported a failure in its progress stream.
102 #[error("image build failed: {0}")]
103 BuildFailed(String),
104
105 /// The provided [`crate::ContainerSpec`] is structurally invalid.
106 #[error("invalid container spec: {0}")]
107 InvalidSpec(String),
108}