Skip to main content

agent_protocols/
error.rs

1use thiserror::Error;
2
3pub type Result<T> = std::result::Result<T, SdkError>;
4
5#[derive(Debug, Error)]
6pub enum SdkError {
7    #[error("invalid agent id: {0}")]
8    InvalidAgentId(String),
9
10    #[error("agent id must start with did:agent:")]
11    InvalidAgentIdPrefix,
12
13    #[error("invalid public key length: expected 32 bytes, got {0}")]
14    InvalidPublicKeyLength(usize),
15
16    #[error("canonical JSON error: {0}")]
17    CanonicalJson(String),
18
19    #[error("JSON error: {0}")]
20    Json(#[from] serde_json::Error),
21
22    #[error("base64url decode error: {0}")]
23    Base64(#[from] base64::DecodeError),
24
25    #[error("Ed25519 error: {0}")]
26    Ed25519(#[from] ed25519_dalek::SignatureError),
27
28    #[error("random generation error: {0}")]
29    Random(String),
30
31    #[error("invalid signature length: expected 64 bytes, got {0}")]
32    InvalidSignatureLength(usize),
33
34    #[error("invalid event hash: expected {expected}, got {actual}")]
35    InvalidEventHash { expected: String, actual: String },
36
37    #[error("invalid event protocol: expected {expected}, got {actual}")]
38    InvalidEventProtocol { expected: String, actual: String },
39
40    #[error("invalid event type: expected {expected}, got {actual}")]
41    InvalidEventType { expected: String, actual: String },
42
43    #[error("invalid actor: {0}")]
44    InvalidActor(String),
45
46    #[error("timestamp is outside the allowed live-write window")]
47    TimestampOutOfWindow,
48
49    #[error("invalid nonce: {0}")]
50    InvalidNonce(String),
51
52    #[error("nonce must be greater than accepted max nonce {max_nonce}")]
53    NonceNotGreater { max_nonce: u64 },
54
55    #[error("event requires a room_id")]
56    MissingRoomId,
57
58    #[error("room id mismatch: expected {expected}, got {actual}")]
59    RoomIdMismatch { expected: String, actual: String },
60
61    #[error("permission denied")]
62    PermissionDenied,
63
64    #[error("invalid payload: {0}")]
65    InvalidPayload(String),
66
67    #[error("invalid JWT: {0}")]
68    InvalidJwt(String),
69
70    #[error("invalid JWT claim: {0}")]
71    InvalidJwtClaim(&'static str),
72
73    #[cfg(feature = "http-client")]
74    #[error("HTTP client error: {0}")]
75    Http(#[from] reqwest::Error),
76}