Skip to main content

ant_core/
error.rs

1use std::path::PathBuf;
2
3#[derive(Debug, thiserror::Error)]
4pub enum Error {
5    #[error("I/O error: {0}")]
6    Io(#[from] std::io::Error),
7
8    #[error("JSON serialization error: {0}")]
9    Json(#[from] serde_json::Error),
10
11    #[error("Node not found: {0}")]
12    NodeNotFound(u32),
13
14    #[error("No node found with service name '{0}'")]
15    NodeNotFoundByName(String),
16
17    #[error("Node already running: {0}")]
18    NodeAlreadyRunning(u32),
19
20    #[error("Node not running: {0}")]
21    NodeNotRunning(u32),
22
23    #[error("Node {0} has been evicted; its data directory was deleted to reclaim disk space. Dismiss it and add a new node instead of restarting.")]
24    NodeEvicted(u32),
25
26    #[error("Daemon already running (pid: {0})")]
27    DaemonAlreadyRunning(u32),
28
29    #[error("Daemon not running")]
30    DaemonNotRunning,
31
32    #[error("Failed to bind to address: {0}")]
33    BindError(String),
34
35    #[error("Port file not found: {0}")]
36    PortFileNotFound(PathBuf),
37
38    #[error("PID file not found: {0}")]
39    PidFileNotFound(PathBuf),
40
41    #[error("HTTP request error: {0}")]
42    HttpRequest(String),
43
44    #[error("Process spawn failed: {0}")]
45    ProcessSpawn(String),
46
47    #[error("Port range length ({range_len}) does not match node count ({count})")]
48    PortRangeMismatch { range_len: u16, count: u16 },
49
50    #[error("Invalid port range: {0}")]
51    InvalidPortRange(String),
52
53    #[error("Invalid env variable format: '{0}'. Expected KEY=VALUE")]
54    InvalidEnvVar(String),
55
56    #[error("Binary not found at path: {0}")]
57    BinaryNotFound(PathBuf),
58
59    #[error("Binary resolution failed: {0}")]
60    BinaryResolution(String),
61
62    #[error("Invalid rewards address: {0}")]
63    InvalidRewardsAddress(String),
64
65    #[error("Failed to stop daemon: {0}")]
66    DaemonStopFailed(String),
67
68    #[error("Could not determine home directory (HOME/USERPROFILE not set)")]
69    HomeDirNotFound,
70
71    #[error("Update failed: {0}")]
72    UpdateFailed(String),
73
74    #[error("Failed to parse bootstrap_peers.toml: {0}")]
75    BootstrapConfigParse(String),
76
77    #[error(
78        "No bootstrap peers available: pass peers explicitly, use a devnet manifest, or install bootstrap_peers.toml in the config directory"
79    )]
80    NoBootstrapPeers,
81
82    #[error(
83        "Devnet manifest contains EVM config but no EVM network was selected: pass 'local' to use the manifest's EVM config, or an explicit preset ('arbitrum-one', 'arbitrum-sepolia') to override it"
84    )]
85    EvmNetworkAmbiguous,
86
87    #[error("Unsupported EVM network: {0}. Use 'arbitrum-one', 'arbitrum-sepolia', or 'local'.")]
88    UnsupportedEvmNetwork(String),
89
90    #[error("EVM network 'local' requires a devnet manifest with EVM info")]
91    EvmManifestRequired,
92
93    #[error("Invalid EVM info in devnet manifest: {0}")]
94    InvalidEvmManifest(String),
95
96    #[error("Node count {count} exceeds maximum of {max} per call")]
97    InvalidNodeCount { count: u16, max: u16 },
98
99    #[error(
100        "Cannot reset while nodes are running ({0} node(s) still running). Stop all nodes first."
101    )]
102    NodesStillRunning(u32),
103
104    #[error("Log forwarding: {0}")]
105    LogForward(String),
106}
107
108pub type Result<T> = std::result::Result<T, Error>;