Skip to main content

ave_common/
error.rs

1//! Error types used by `ave-common`.
2
3use thiserror::Error;
4
5#[cfg(feature = "openapi")]
6use utoipa::ToSchema;
7
8/// Errors returned when converting bridge payloads into internal types.
9#[derive(Debug, Clone, Error)]
10#[cfg_attr(feature = "openapi", derive(ToSchema))]
11pub enum ConversionError {
12    #[error("invalid subject identifier: {0}")]
13    InvalidSubjectId(String),
14
15    #[error("invalid governance identifier: {0}")]
16    InvalidGovernanceId(String),
17
18    #[error("invalid schema identifier: {0}")]
19    InvalidSchemaId(String),
20
21    #[error("invalid public key: {0}")]
22    InvalidPublicKey(String),
23
24    #[error("invalid namespace: {0}")]
25    InvalidNamespace(String),
26
27    #[error("missing governance identifier")]
28    MissingGovernanceId,
29
30    #[error("missing namespace")]
31    MissingNamespace,
32}
33
34/// Errors returned when decoding API-facing signatures.
35#[derive(Debug, Clone, Error)]
36#[cfg_attr(feature = "openapi", derive(ToSchema))]
37pub enum SignatureError {
38    #[error("invalid public key: {0}")]
39    InvalidPublicKey(String),
40
41    #[error("invalid signature value: {0}")]
42    InvalidSignature(String),
43
44    #[error("invalid content hash: {0}")]
45    InvalidContentHash(String),
46}
47
48/// Top-level error type for this crate.
49#[derive(Error, Debug, Clone)]
50#[cfg_attr(feature = "openapi", derive(ToSchema))]
51pub enum Error {
52    /// Bridge error
53    #[error("bridge error: {0}")]
54    Bridge(String),
55
56    /// Serialization/Deserialization error
57    #[error("serde error: {0}")]
58    Serde(String),
59
60    /// Invalid identifier error
61    #[error("invalid identifier: {0}")]
62    InvalidIdentifier(String),
63
64    /// Conversion error
65    #[error("conversion error: {0}")]
66    Conversion(#[from] ConversionError),
67
68    /// Signature error
69    #[error("signature error: {0}")]
70    Signature(#[from] SignatureError),
71
72    /// Generic error
73    #[error("{0}")]
74    Generic(String),
75}
76
77impl From<serde_json::Error> for Error {
78    fn from(err: serde_json::Error) -> Self {
79        Self::Serde(err.to_string())
80    }
81}