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("invalid viewpoints: {0}")]
28    InvalidViewpoints(String),
29
30    #[error("missing governance identifier")]
31    MissingGovernanceId,
32
33    #[error("missing namespace")]
34    MissingNamespace,
35}
36
37/// Errors returned when decoding API-facing signatures.
38#[derive(Debug, Clone, Error)]
39#[cfg_attr(feature = "openapi", derive(ToSchema))]
40pub enum SignatureError {
41    #[error("invalid public key: {0}")]
42    InvalidPublicKey(String),
43
44    #[error("invalid signature value: {0}")]
45    InvalidSignature(String),
46
47    #[error("invalid content hash: {0}")]
48    InvalidContentHash(String),
49}
50
51/// Top-level error type for this crate.
52#[derive(Error, Debug, Clone)]
53#[cfg_attr(feature = "openapi", derive(ToSchema))]
54pub enum Error {
55    /// Bridge error
56    #[error("bridge error: {0}")]
57    Bridge(String),
58
59    /// Serialization/Deserialization error
60    #[error("serde error: {0}")]
61    Serde(String),
62
63    /// Invalid identifier error
64    #[error("invalid identifier: {0}")]
65    InvalidIdentifier(String),
66
67    /// Conversion error
68    #[error("conversion error: {0}")]
69    Conversion(#[from] ConversionError),
70
71    /// Signature error
72    #[error("signature error: {0}")]
73    Signature(#[from] SignatureError),
74
75    /// Generic error
76    #[error("{0}")]
77    Generic(String),
78}
79
80impl From<serde_json::Error> for Error {
81    fn from(err: serde_json::Error) -> Self {
82        Self::Serde(err.to_string())
83    }
84}