1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/// Comprehensive error handling for the unified refactoring engine.
///
/// This enum covers all possible failure modes during refactoring operations,
/// from state machine transitions to I/O operations and code analysis.
/// Each variant provides detailed context about the specific failure.
///
/// # Error Recovery
///
/// The engine implements different recovery strategies based on error type:
/// - **`StateMachine` errors**: Rollback to last checkpoint
/// - **IO errors**: Retry with exponential backoff
/// - **Serialization errors**: Graceful degradation to simplified format
/// - **Analysis errors**: Skip problematic files and continue
///
/// # Examples
///
/// ```rust,no_run
/// use pmat::services::refactor_engine::EngineError;
///
/// // State machine errors
/// let state_error = EngineError::StateMachine(
/// "Invalid transition from Analyze to Complete".to_string()
/// );
/// assert_eq!(
/// state_error.to_string(),
/// "State machine error: Invalid transition from Analyze to Complete"
/// );
///
/// // IO errors are automatically converted
/// let io_error: EngineError = std::io::Error::new(
/// std::io::ErrorKind::NotFound,
/// "File not found"
/// ).into();
/// assert!(io_error.to_string().contains("IO error:"));
///
/// // Analysis errors with context
/// let analysis_error = EngineError::Analysis(
/// "Failed to parse AST: unexpected token".to_string()
/// );
/// assert!(analysis_error.to_string().contains("Analysis error:"));
/// ```
#[derive(Debug, thiserror::Error)]
pub enum EngineError {
#[error("State machine error: {0}")]
StateMachine(String),
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
#[error("Serialization error: {0}")]
Serialization(#[from] serde_json::Error),
#[error("Analysis error: {0}")]
Analysis(String),
}
impl From<String> for EngineError {
fn from(s: String) -> Self {
EngineError::StateMachine(s)
}
}