Skip to content

Commit 74cffc0

Browse files
Copilotjosecelano
andcommitted
refactor: [#56] migrate DestroyCommandHandler to modular structure
Split destroy.rs (631 lines) into modular directory structure: - destroy/mod.rs - Module documentation and public API - destroy/handler.rs - Command handler implementation - destroy/errors.rs - Error types with Traceable impl - destroy/tests/ - Test organization (builders, integration) All existing tests pass. No changes to business logic. Co-authored-by: josecelano <58816+josecelano@users.noreply.github.com>
1 parent ece9119 commit 74cffc0

6 files changed

Lines changed: 346 additions & 265 deletions

File tree

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
//! Error types for the Destroy command handler
2+
3+
use std::path::PathBuf;
4+
5+
use crate::adapters::tofu::client::OpenTofuError;
6+
use crate::domain::environment::state::StateTypeError;
7+
use crate::shared::command::CommandError;
8+
9+
/// Comprehensive error type for the `DestroyCommandHandler`
10+
#[derive(Debug, thiserror::Error)]
11+
pub enum DestroyCommandHandlerError {
12+
#[error("OpenTofu command failed: {0}")]
13+
OpenTofu(#[from] OpenTofuError),
14+
15+
#[error("Command execution failed: {0}")]
16+
Command(#[from] CommandError),
17+
18+
#[error("Failed to persist environment state: {0}")]
19+
StatePersistence(#[from] crate::domain::environment::repository::RepositoryError),
20+
21+
#[error("Invalid state transition: {0}")]
22+
StateTransition(#[from] StateTypeError),
23+
24+
#[error("Failed to clean up state files at '{path}': {source}")]
25+
StateCleanupFailed {
26+
path: PathBuf,
27+
#[source]
28+
source: std::io::Error,
29+
},
30+
}
31+
32+
impl crate::shared::Traceable for DestroyCommandHandlerError {
33+
fn trace_format(&self) -> String {
34+
match self {
35+
Self::OpenTofu(e) => {
36+
format!("DestroyCommandHandlerError: OpenTofu command failed - {e}")
37+
}
38+
Self::Command(e) => {
39+
format!("DestroyCommandHandlerError: Command execution failed - {e}")
40+
}
41+
Self::StatePersistence(e) => {
42+
format!("DestroyCommandHandlerError: Failed to persist environment state - {e}")
43+
}
44+
Self::StateTransition(e) => {
45+
format!("DestroyCommandHandlerError: Invalid state transition - {e}")
46+
}
47+
Self::StateCleanupFailed { path, source } => {
48+
format!(
49+
"DestroyCommandHandlerError: Failed to clean up state files at '{}' - {source}",
50+
path.display()
51+
)
52+
}
53+
}
54+
}
55+
56+
fn trace_source(&self) -> Option<&dyn crate::shared::Traceable> {
57+
match self {
58+
Self::OpenTofu(e) => Some(e),
59+
Self::Command(e) => Some(e),
60+
Self::StatePersistence(_)
61+
| Self::StateTransition(_)
62+
| Self::StateCleanupFailed { .. } => None,
63+
}
64+
}
65+
66+
fn error_kind(&self) -> crate::shared::ErrorKind {
67+
match self {
68+
Self::OpenTofu(_) => crate::shared::ErrorKind::InfrastructureOperation,
69+
Self::Command(_) => crate::shared::ErrorKind::CommandExecution,
70+
Self::StateTransition(_) => crate::shared::ErrorKind::Configuration,
71+
Self::StatePersistence(_) | Self::StateCleanupFailed { .. } => {
72+
crate::shared::ErrorKind::StatePersistence
73+
}
74+
}
75+
}
76+
}

0 commit comments

Comments
 (0)