ant_core/error.rs
1//! Error types module
2//!
3//! This module contains error types used throughout the P2P Foundation.
4
5/// Main error type for P2P Foundation
6#[derive(Debug, thiserror::Error)]
7pub enum P2PError {
8 /// Network-related error (connections, peers, protocols)
9 #[error("Network error: {0}")]
10 Network(String),
11
12 /// DHT operation error (lookups, storage, routing)
13 #[error("DHT error: {0}")]
14 DHT(String),
15
16 /// Transport layer error (QUIC, TCP, tunneling)
17 #[error("Transport error: {0}")]
18 Transport(String),
19
20 /// Security-related error (authentication, encryption, validation)
21 #[error("Security error: {0}")]
22 Security(String),
23
24 /// MCP server error (tool calls, message routing)
25 #[error("MCP error: {0}")]
26 MCP(String),
27
28 /// Bootstrap cache error (peer discovery, cache management)
29 #[error("Bootstrap error: {0}")]
30 Bootstrap(String),
31
32 /// Configuration error (invalid settings, missing parameters)
33 #[error("Configuration error: {0}")]
34 Config(String),
35
36 /// Cryptography error (key generation, encryption, signatures)
37 #[error("Cryptography error: {0}")]
38 Cryptography(String),
39
40 /// Invalid state error (operations in wrong state)
41 #[error("Invalid state: {0}")]
42 InvalidState(String),
43
44 /// Invalid input error (bad parameters, malformed data)
45 #[error("Invalid input: {0}")]
46 InvalidInput(String),
47
48 /// IO error (file operations, network IO)
49 #[error("IO error: {0}")]
50 IO(#[from] std::io::Error),
51
52 /// Serialization error (JSON, protocol encoding/decoding)
53 #[error("Serialization error: {0}")]
54 Serialization(#[from] serde_json::Error),
55
56 /// Generic error (catch-all for other error types)
57 #[error("Generic error: {0}")]
58 Generic(#[from] anyhow::Error),
59}
60
61/// Result type alias for P2P Foundation operations
62pub type Result<T> = std::result::Result<T, P2PError>;