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    // ── History ──────────────────────────────────────────────────
78    #[error("SQLite error: {0}")]
79    Sqlite(#[from] rusqlite::Error),
80
81    // ── Execution ────────────────────────────────────────────────
82    #[error("Command execution error: {0}")]
83    Command(String),
84
85    #[error("Subprocess error: {0}")]
86    Subprocess(String),
87
88    #[error("Timeout: {0}")]
89    Timeout(String),
90
91    // ── Internal ─────────────────────────────────────────────────
92    #[error("Internal error: {0}")]
93    Internal(String),
94
95    #[error("Not implemented: {0}")]
96    NotImplemented(String),
97
98    #[error("{0}")]
99    Anyhow(#[from] anyhow::Error),
100}
101
102/// Convenience alias.
103pub type Result<T> = std::result::Result<T, ForgeGuardError>;