Skip to content

Commit f3cf20b

Browse files
committed
refactor: extract error and timeout types to dedicated modules
- Move all error types (ContainerError, ContainerImageError, etc.) to src/e2e/containers/errors.rs - Move ContainerTimeouts to src/e2e/containers/timeout.rs - Rename ProvisionedContainerError to ContainerError for better naming - Clean up provisioned.rs by removing ~175 lines of type definitions - Re-export types from containers/mod.rs for backward compatibility - Update imports and documentation examples - All tests passing, full backward compatibility maintained
1 parent b0b3bc5 commit f3cf20b

File tree

5 files changed

+345
-156
lines changed

5 files changed

+345
-156
lines changed

src/e2e/containers/errors.rs

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
//! Error types for provisioned container operations
2+
//!
3+
//! This module contains all error types related to container provisioning and management.
4+
//! The errors are organized by logical problem categories to make troubleshooting easier.
5+
6+
/// Top-level error type for container operations
7+
///
8+
/// This error type organizes failures by what logically went wrong, making it easier
9+
/// to understand and troubleshoot issues during container provisioning.
10+
#[derive(Debug, thiserror::Error)]
11+
pub enum ContainerError {
12+
/// Problems with the Docker image (build failures, Docker daemon issues)
13+
#[error("Container image problem: {source}")]
14+
ContainerImage {
15+
#[from]
16+
source: ContainerImageError,
17+
},
18+
19+
/// Problems with container runtime (startup, configuration)
20+
#[error("Container runtime problem: {source}")]
21+
ContainerRuntime {
22+
#[from]
23+
source: ContainerRuntimeError,
24+
},
25+
26+
/// Problems with container networking (port mapping, connectivity)
27+
#[error("Container networking problem: {source}")]
28+
ContainerNetworking {
29+
#[from]
30+
source: ContainerNetworkingError,
31+
},
32+
33+
/// Problems with SSH setup and connectivity
34+
#[error("SSH setup problem: {source}")]
35+
SshSetup {
36+
#[from]
37+
source: SshSetupError,
38+
},
39+
}
40+
41+
/// Container image-related errors
42+
///
43+
/// These errors occur when there are problems with the Docker image that needs to run.
44+
/// This includes building the image, Docker daemon issues, or missing dependencies.
45+
#[derive(Debug, thiserror::Error)]
46+
pub enum ContainerImageError {
47+
/// Docker image build process failed
48+
#[error("Failed to build Docker image '{image_name}:{image_tag}': {reason}")]
49+
BuildFailed {
50+
image_name: String,
51+
image_tag: String,
52+
reason: String,
53+
#[source]
54+
source: super::image_builder::ContainerBuildError,
55+
},
56+
57+
/// Docker daemon or command execution issues
58+
#[error("Docker command execution failed for image '{image_name}:{image_tag}': {reason}")]
59+
DockerCommandFailed {
60+
image_name: String,
61+
image_tag: String,
62+
reason: String,
63+
#[source]
64+
source: std::io::Error,
65+
},
66+
}
67+
68+
/// Container runtime errors
69+
///
70+
/// These errors occur during container lifecycle operations - starting, configuring,
71+
/// or managing the running container.
72+
#[derive(Debug, thiserror::Error)]
73+
pub enum ContainerRuntimeError {
74+
/// Container configuration is invalid or malformed
75+
#[error("Invalid container configuration for image '{image_name}:{image_tag}': {reason}")]
76+
InvalidConfiguration {
77+
image_name: String,
78+
image_tag: String,
79+
reason: String,
80+
#[source]
81+
source: super::config_builder::ContainerConfigError,
82+
},
83+
84+
/// Container failed to start or reach expected state
85+
#[error("Container failed to start for image '{image_name}:{image_tag}': {reason}")]
86+
StartupFailed {
87+
image_name: String,
88+
image_tag: String,
89+
reason: String,
90+
#[source]
91+
source: testcontainers::TestcontainersError,
92+
},
93+
}
94+
95+
/// Container networking errors
96+
///
97+
/// These errors occur when there are problems with container network access,
98+
/// port mapping, or connectivity.
99+
#[derive(Debug, thiserror::Error)]
100+
pub enum ContainerNetworkingError {
101+
/// Failed to get mapped ports from container
102+
#[error("Failed to get mapped port {internal_port} from container '{container_id}': {reason}")]
103+
PortMappingFailed {
104+
container_id: String,
105+
internal_port: u16,
106+
reason: String,
107+
#[source]
108+
source: testcontainers::TestcontainersError,
109+
},
110+
}
111+
112+
/// SSH setup and connectivity errors
113+
///
114+
/// These errors occur when setting up or testing SSH access to the container.
115+
/// This includes SSH service readiness, key setup, and connection testing.
116+
#[derive(Debug, thiserror::Error)]
117+
pub enum SshSetupError {
118+
/// SSH service not ready within timeout
119+
#[error(
120+
"SSH service not ready on container '{container_id}' port {ssh_port} after {timeout_secs}s"
121+
)]
122+
ServiceTimeout {
123+
container_id: String,
124+
ssh_port: u16,
125+
timeout_secs: u64,
126+
},
127+
128+
/// SSH key setup failed inside container
129+
#[error("Failed to setup SSH keys in container '{container_id}': {reason}")]
130+
KeySetupFailed {
131+
container_id: String,
132+
reason: String,
133+
#[source]
134+
source: super::actions::ssh_key_setup::SshKeySetupError,
135+
},
136+
137+
/// SSH connectivity test failed
138+
#[error(
139+
"SSH connectivity test failed for container '{container_id}' on port {ssh_port}: {reason}"
140+
)]
141+
ConnectivityTestFailed {
142+
container_id: String,
143+
ssh_port: u16,
144+
reason: String,
145+
#[source]
146+
source: super::actions::ssh_wait::SshWaitError,
147+
},
148+
}
149+
150+
/// Result type alias for container operations
151+
pub type Result<T> = std::result::Result<T, Box<ContainerError>>;

src/e2e/containers/mod.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,27 @@
2525
//!
2626
//! ```rust,no_run
2727
//! use torrust_tracker_deploy::e2e::containers::{
28-
//! StoppedProvisionedContainer, RunningProvisionedContainer, ProvisionedContainerError,
28+
//! StoppedProvisionedContainer, RunningProvisionedContainer, ContainerError,
2929
//! ContainerImageBuilder, ContainerConfigBuilder
3030
//! };
3131
//! ```
3232
3333
pub mod actions;
3434
pub mod config_builder;
35+
pub mod errors;
3536
pub mod executor;
3637
pub mod image_builder;
3738
pub mod provisioned;
39+
pub mod timeout;
3840

3941
// Re-export provisioned container types for backward compatibility
40-
pub use provisioned::{
41-
ContainerTimeouts, ProvisionedContainerError, Result, RunningProvisionedContainer,
42-
StoppedProvisionedContainer,
43-
};
42+
pub use provisioned::{RunningProvisionedContainer, StoppedProvisionedContainer};
43+
44+
// Re-export error types for public use
45+
pub use errors::{ContainerError, Result};
46+
47+
// Re-export timeout types for public use
48+
pub use timeout::ContainerTimeouts;
4449

4550
// Re-export docker builder for public use
4651
pub use image_builder::{ContainerBuildError, ContainerImageBuilder};

0 commit comments

Comments
 (0)