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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//! Error types for Forge
//!
//! ## Table of Contents
//! - **ForgeError**: Main error enum covering all failure modes
//! - **Result**: Type alias for `Result<T, ForgeError>`
use thiserror::Error;
/// Result type alias for Forge operations
pub type Result<T> = std::result::Result<T, ForgeError>;
/// Main error type for Forge operations
#[derive(Error, Debug)]
pub enum ForgeError {
/// Configuration error during builder setup
#[error("configuration error: {0}")]
Config(String),
/// Nomad API communication failure
#[error("nomad error: {0}")]
Nomad(String),
/// Storage backend failure (RocksDB or etcd)
#[error("storage error: {0}")]
Storage(String),
/// Networking failure (QUIC, HTTP, gRPC)
#[error("network error: {0}")]
Network(String),
/// Consensus/Raft failure
#[error("consensus error: {0}")]
Consensus(String),
/// MoE routing failure
#[error("routing error: {0}")]
Routing(String),
/// Job submission or management failure
#[error("job error: {0}")]
Job(String),
/// Autoscaling decision failure
#[error("autoscaler error: {0}")]
Autoscaler(String),
/// Metrics collection or export failure
#[error("metrics error: {0}")]
Metrics(String),
/// Runtime not initialized or already stopped
#[error("runtime error: {0}")]
Runtime(String),
/// Generic IO error
#[error("io error: {0}")]
Io(#[from] std::io::Error),
/// Serialization/deserialization error
#[error("serialization error: {0}")]
Serialization(#[from] serde_json::Error),
/// Internal error (should not occur in normal operation)
#[error("internal error: {0}")]
Internal(String),
}
impl ForgeError {
/// Create a configuration error
pub fn config(msg: impl Into<String>) -> Self {
Self::Config(msg.into())
}
/// Create a Nomad error
pub fn nomad(msg: impl Into<String>) -> Self {
Self::Nomad(msg.into())
}
/// Create a storage error
pub fn storage(msg: impl Into<String>) -> Self {
Self::Storage(msg.into())
}
/// Create a network error
pub fn network(msg: impl Into<String>) -> Self {
Self::Network(msg.into())
}
/// Create a job error
pub fn job(msg: impl Into<String>) -> Self {
Self::Job(msg.into())
}
/// Create a runtime error
pub fn runtime(msg: impl Into<String>) -> Self {
Self::Runtime(msg.into())
}
/// Create a metrics error
pub fn metrics(msg: impl Into<String>) -> Self {
Self::Metrics(msg.into())
}
}
impl From<reqwest::Error> for ForgeError {
fn from(err: reqwest::Error) -> Self {
Self::Network(err.to_string())
}
}
impl From<prometheus::Error> for ForgeError {
fn from(err: prometheus::Error) -> Self {
Self::Metrics(err.to_string())
}
}