Maintain/Run/Error.rs
1//=============================================================================//
2// File Path: Element/Maintain/Source/Run/Error.rs
3//=============================================================================//
4// Module: Error
5//
6// Brief Description: Error types for the Run module.
7//
8// RESPONSIBILITIES:
9// ================
10//
11// Primary:
12// - Define comprehensive error types for run operations
13// - Provide error conversion and display implementations
14// - Enable proper error propagation throughout the run module
15//
16// Secondary:
17// - Support error context and chaining
18// - Provide user-friendly error messages
19//
20// ARCHITECTURAL ROLE:
21// ===================
22//
23// Position:
24// - Infrastructure/Error handling layer
25// - Error type definitions
26//
27// Dependencies (What this module requires):
28// - External crates: thiserror, std
29// - Internal modules: None
30// - Traits implemented: Display, Error, From
31//
32// Dependents (What depends on this module):
33// - Run orchestration functions
34// - Process management
35// - Profile resolution
36//
37//=============================================================================//
38// IMPLEMENTATION
39//=============================================================================//
40
41use std::{io, path::PathBuf};
42
43use thiserror::Error as ThisError;
44
45/// Comprehensive error type for run operations.
46///
47/// This enum represents all possible errors that can occur during
48/// the development run process. Each variant provides context-specific
49/// information for debugging and error recovery.
50#[derive(Debug, ThisError)]
51pub enum Error {
52 /// Error when a configuration file is not found or cannot be read.
53 #[error("Configuration file not found or unreadable: {0}")]
54 ConfigNotFound(PathBuf),
55
56 /// Error when parsing configuration fails.
57 #[error("Failed to parse configuration: {0}")]
58 ConfigParse(String),
59
60 /// Error when a profile is not found in the configuration.
61 #[error("Profile '{0}' not found. Available profiles: {1}")]
62 ProfileNotFound(String, String),
63
64 /// Error when environment variable resolution fails.
65 #[error("Failed to resolve environment variables: {0}")]
66 EnvResolve(String),
67
68 /// Error when a required environment variable is missing.
69 #[error("Required environment variable '{0}' is not set")]
70 EnvMissing(String),
71
72 /// Error when file system operations fail.
73 #[error("File system error: {0}")]
74 Io(#[from] io::Error),
75
76 /// Error when JSON parsing fails.
77 #[error("JSON parsing error: {0}")]
78 Json(#[from] serde_json::Error),
79
80 /// Error when a process fails to start.
81 #[error("Failed to start process: {0}")]
82 ProcessStart(String),
83
84 /// Error when a process exits with a non-zero status.
85 #[error("Process exited with code: {0}")]
86 ProcessExit(i32),
87
88 /// Error when a process is terminated by a signal.
89 #[error("Process terminated by signal: {0}")]
90 ProcessSignal(String),
91
92 /// Error when port binding fails.
93 #[error("Failed to bind to port {0}: {1}")]
94 PortBind(u16, String),
95
96 /// Error when hot-reload setup fails.
97 #[error("Hot-reload setup failed: {0}")]
98 HotReload(String),
99
100 /// Error when watch mode setup fails.
101 #[error("Watch mode setup failed: {0}")]
102 WatchMode(String),
103
104 /// Error when a dependency is not found.
105 #[error("Dependency not found: {0}")]
106 DependencyNotFound(String),
107
108 /// Error when an invalid argument is provided.
109 #[error("Invalid argument: {0}")]
110 InvalidArgument(String),
111
112 /// Error when run configuration is invalid.
113 #[error("Invalid run configuration: {0}")]
114 InvalidConfig(String),
115
116 /// Error when multiple conflicting options are provided.
117 #[error("Conflicting options: {0}")]
118 ConflictingOptions(String),
119}
120
121/// Result type alias for run operations.
122///
123/// This type alias simplifies function signatures by providing
124/// a shorthand for `Result<T, Error>`.
125pub type Result<T> = std::result::Result<T, Error>;