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 thiserror::Error as ThisError;
42use std::{io, path::PathBuf};
43
44/// Comprehensive error type for run operations.
45///
46/// This enum represents all possible errors that can occur during
47/// the development run process. Each variant provides context-specific
48/// information for debugging and error recovery.
49#[derive(Debug, ThisError)]
50pub enum Error {
51 /// Error when a configuration file is not found or cannot be read.
52 #[error("Configuration file not found or unreadable: {0}")]
53 ConfigNotFound(PathBuf),
54
55 /// Error when parsing configuration fails.
56 #[error("Failed to parse configuration: {0}")]
57 ConfigParse(String),
58
59 /// Error when a profile is not found in the configuration.
60 #[error("Profile '{0}' not found. Available profiles: {1}")]
61 ProfileNotFound(String, String),
62
63 /// Error when environment variable resolution fails.
64 #[error("Failed to resolve environment variables: {0}")]
65 EnvResolve(String),
66
67 /// Error when a required environment variable is missing.
68 #[error("Required environment variable '{0}' is not set")]
69 EnvMissing(String),
70
71 /// Error when file system operations fail.
72 #[error("File system error: {0}")]
73 Io(#[from] io::Error),
74
75 /// Error when JSON parsing fails.
76 #[error("JSON parsing error: {0}")]
77 Json(#[from] serde_json::Error),
78
79 /// Error when a process fails to start.
80 #[error("Failed to start process: {0}")]
81 ProcessStart(String),
82
83 /// Error when a process exits with a non-zero status.
84 #[error("Process exited with code: {0}")]
85 ProcessExit(i32),
86
87 /// Error when a process is terminated by a signal.
88 #[error("Process terminated by signal: {0}")]
89 ProcessSignal(String),
90
91 /// Error when port binding fails.
92 #[error("Failed to bind to port {0}: {1}")]
93 PortBind(u16, String),
94
95 /// Error when hot-reload setup fails.
96 #[error("Hot-reload setup failed: {0}")]
97 HotReload(String),
98
99 /// Error when watch mode setup fails.
100 #[error("Watch mode setup failed: {0}")]
101 WatchMode(String),
102
103 /// Error when a dependency is not found.
104 #[error("Dependency not found: {0}")]
105 DependencyNotFound(String),
106
107 /// Error when an invalid argument is provided.
108 #[error("Invalid argument: {0}")]
109 InvalidArgument(String),
110
111 /// Error when run configuration is invalid.
112 #[error("Invalid run configuration: {0}")]
113 InvalidConfig(String),
114
115 /// Error when multiple conflicting options are provided.
116 #[error("Conflicting options: {0}")]
117 ConflictingOptions(String),
118}
119
120/// Result type alias for run operations.
121///
122/// This type alias simplifies function signatures by providing
123/// a shorthand for `Result<T, Error>`.
124pub type Result<T> = std::result::Result<T, Error>;