|
| 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>>; |
0 commit comments