Skip to main content

forge_guard/core/
error.rs

1use thiserror::Error;
2
3/// Unified error type for all forge-guard operations.
4#[derive(Error, Debug)]
5pub enum ForgeGuardError {
6    // ── I/O & Filesystem ──────────────────────────────────────────
7    #[error("I/O error: {0}")]
8    Io(#[from] std::io::Error),
9
10    #[error("File not found: {0}")]
11    FileNotFound(String),
12
13    #[error("Invalid path: {0}")]
14    InvalidPath(String),
15
16    // ── Parsing ──────────────────────────────────────────────────
17    #[error("Parse error: {0}")]
18    Parse(String),
19
20    #[error("TOML parse error: {0}")]
21    Toml(#[from] toml::de::Error),
22
23    #[error("JSON parse error: {0}")]
24    Json(#[from] serde_json::Error),
25
26    #[error("Regex error: {0}")]
27    Regex(#[from] regex::Error),
28
29    // ── Security ─────────────────────────────────────────────────
30    #[error("Security check failed: {0}")]
31    SecurityCheck(String),
32
33    #[error("Critical vulnerability found: {0}")]
34    CriticalVulnerability(String),
35
36    #[error("Deployment blocked: {0}")]
37    DeploymentBlocked(String),
38
39    // ── Analysis ─────────────────────────────────────────────────
40    #[error("Analysis error: {0}")]
41    Analysis(String),
42
43    #[error("AST parsing error: {0}")]
44    AstParse(String),
45
46    #[error("Bytecode analysis error: {0}")]
47    BytecodeAnalysis(String),
48
49    // ── Chain ────────────────────────────────────────────────────
50    #[error("Unsupported chain: {0}")]
51    UnsupportedChain(String),
52
53    #[error("RPC error: {0}")]
54    Rpc(String),
55
56    // ── Plugin ───────────────────────────────────────────────────
57    #[error("Plugin error: {0}")]
58    Plugin(String),
59
60    #[error("Plugin not found: {0}")]
61    PluginNotFound(String),
62
63    #[error("Plugin load error: {0}")]
64    PluginLoad(String),
65
66    // ── Configuration ────────────────────────────────────────────
67    #[error("Configuration error: {0}")]
68    Config(String),
69
70    #[error("Environment error: {0}")]
71    Env(String),
72
73    // ── Cache ────────────────────────────────────────────────────
74    #[error("Cache error: {0}")]
75    Cache(String),
76
77    // ── Execution ────────────────────────────────────────────────
78    #[error("Command execution error: {0}")]
79    Command(String),
80
81    #[error("Subprocess error: {0}")]
82    Subprocess(String),
83
84    #[error("Timeout: {0}")]
85    Timeout(String),
86
87    // ── Internal ─────────────────────────────────────────────────
88    #[error("Internal error: {0}")]
89    Internal(String),
90
91    #[error("Not implemented: {0}")]
92    NotImplemented(String),
93
94    #[error("{0}")]
95    Anyhow(#[from] anyhow::Error),
96}
97
98/// Convenience alias.
99pub type Result<T> = std::result::Result<T, ForgeGuardError>;