Skip to main content

ave_common/
error.rs

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