regent_sdk/error.rs
1//! Error types for Regent SDK
2//!
3//! This module provides comprehensive error handling for all operations
4//! within the Regent SDK. All errors implement `std::error::Error` and
5//! provide detailed context for troubleshooting.
6
7use thiserror::Error;
8
9/// The primary error type for Regent SDK operations.
10///
11/// All operations in Regent SDK return this error type, which provides
12/// detailed information about what went wrong during execution.
13///
14/// # Error Variants
15///
16/// - `FailureToFindGroupContent`: Could not locate group information
17/// - `FailureToParseContent`: Parsing errors (YAML, JSON, etc.)
18/// - `FailureToRunCommand`: Command execution failed
19/// - `FailureToEstablishConnection`: Connection to host failed
20/// - `FailedInitialization`: Initialization or setup error
21/// - `FailedTcpBinding`: TCP binding failed
22/// - `FailedTaskDryRun`: Dry run of a task failed
23/// - `FailedDryRunEvaluation`: Evaluation during dry run failed
24/// - `FailedToApplyExpectedState`: Could not apply the expected state
25/// - `FailedToGetSecret`: Secret retrieval failed
26/// - `FailureToConsiderContext`: Template context rendering failed
27/// - `MissingInitialization`: Required initialization was missing
28/// - `GroupNotFound`: Requested group does not exist
29/// - `MissingGroupsList`: Groups list was not provided
30/// - `WorkFlowNotFollowed`: Required workflow was not followed
31/// - `WrongInitialization`: Initialization was incorrect
32/// - `AnyOtherError`: Generic error wrapper
33/// - `IncoherentExpectedState`: Expected state definition was inconsistent
34/// - `InternalLogicError`: Internal library error (please report)
35/// - `NotConnectedToHost`: Operation attempted without active connection
36/// - `ProblemWithHostConnection`: Connection issue with host
37/// - `SecretsIssue`: Problem with secret management
38/// - `AttributeError`: Issue with an attribute definition or execution
39/// - `TimeOutReached`: Operation timed out
40///
41/// # Example
42///
43/// ```no_run
44/// use regent_sdk::RegentError;
45///
46/// fn handle_error(e: RegentError) {
47/// match e {
48/// RegentError::NotConnectedToHost => {
49/// eprintln!("Please connect to the host first");
50/// }
51/// RegentError::TimeOutReached(msg) => {
52/// eprintln!("Operation timed out: {}", msg);
53/// }
54/// RegentError::FailedToGetSecret(msg) => {
55/// eprintln!("Secret retrieval failed: {}", msg);
56/// }
57/// _ => {
58/// eprintln!("An error occurred: {:?}", e);
59/// }
60/// }
61/// }
62/// ```
63#[derive(Debug, Error, Clone)]
64pub enum RegentError {
65 #[error("Failure to find group content")]
66 FailureToFindGroupContent,
67
68 #[error("Failure to parse content: '{0}'")]
69 FailureToParseContent(String),
70
71 #[error("Failure to run command: '{0}'")]
72 FailureToRunCommand(String),
73
74 #[error("Failure to establish connection: '{0}'")]
75 FailureToEstablishConnection(String),
76
77 #[error("Failed initialization: '{0}'")]
78 FailedInitialization(String),
79
80 #[error("Failed TCP binding: '{0}'")]
81 FailedTcpBinding(String),
82
83 #[error("Failed task dry run: '{0}'")]
84 FailedTaskDryRun(String),
85
86 #[error("Failed dry run evaluation: '{0}'")]
87 FailedDryRunEvaluation(String),
88
89 #[error("Failed to apply expected state: '{0}'")]
90 FailedToApplyExpectedState(String),
91
92 #[error("Failed to get secret: '{0}'")]
93 FailedToGetSecret(String),
94
95 #[error("Failure to consider context: '{0}'")]
96 FailureToConsiderContext(String),
97 #[error("Missing initialization: '{0}'")]
98 MissingInitialization(String),
99
100 #[error("Group not found")]
101 GroupNotFound,
102
103 #[error("Missing groups list")]
104 MissingGroupsList,
105
106 #[error("Workflow not followed: '{0}'")]
107 WorkFlowNotFollowed(String),
108
109 #[error("Wrong initialization: '{0}'")]
110 WrongInitialization(String),
111
112 #[error("Any other error: '{0}'")]
113 AnyOtherError(String),
114 #[error("Incoherent expected state: '{0}'")]
115 IncoherentExpectedState(String),
116
117 #[error("Internal logic error: '{0}'")]
118 InternalLogicError(String),
119
120 #[error("Not connected to host")]
121 NotConnectedToHost,
122
123 #[error("Problem with host connection: '{0}'")]
124 ProblemWithHostConnection(String),
125
126 #[error("Secrets issue: '{0}'")]
127 SecretsIssue(String),
128
129 #[error("Attribute error: '{0}'")]
130 AttributeError(String),
131
132 #[error("TimeOut reached: '{0}'")]
133 TimeOutReached(String),
134
135 #[error("Failed to get file: '{0}'")]
136 FailedToGetFile(String),
137
138 #[error("Incompatible host: '{0}'")]
139 IncompatibleHost(String),
140}