Skip to main content

icydb_schema/
error.rs

1//! Typed failures at the public proposal-contract boundary.
2
3use std::fmt::{self, Display, Formatter};
4
5use thiserror::Error;
6
7/// Compact scalar parsing failure.
8#[derive(Clone, Copy, Debug, Eq, PartialEq)]
9pub enum TypeParseError {
10    /// Date text is invalid.
11    InvalidDate,
12    /// Decimal text is invalid.
13    InvalidDecimal,
14    /// Duration text is invalid.
15    InvalidDuration,
16    /// Signed big-integer text is invalid.
17    InvalidIntBig,
18    /// Timestamp text is invalid.
19    InvalidTimestamp,
20}
21
22impl Display for TypeParseError {
23    fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
24        formatter.write_str(match self {
25            Self::InvalidDate => "invalid date",
26            Self::InvalidDecimal => "invalid decimal",
27            Self::InvalidDuration => "invalid duration",
28            Self::InvalidIntBig => "invalid signed big integer",
29            Self::InvalidTimestamp => "invalid timestamp",
30        })
31    }
32}
33
34/// Failure while constructing, validating, encoding, or decoding proposal data.
35#[derive(Clone, Debug, Eq, Error, PartialEq)]
36pub enum SchemaContractError {
37    /// A required bounded text identity is empty.
38    #[error("schema contract identity is empty")]
39    EmptyIdentity,
40
41    /// A bounded text identity exceeds its byte limit.
42    #[error("schema contract identity exceeds its byte limit")]
43    IdentityTooLong {
44        /// Actual byte length.
45        len: usize,
46        /// Maximum admitted byte length.
47        max: usize,
48    },
49
50    /// A source key contains a non-canonical byte.
51    #[error("schema source key contains a non-canonical byte")]
52    InvalidSourceKey,
53
54    /// One bounded collection exceeds its item limit.
55    #[error("schema contract collection exceeds its item limit")]
56    TooManyItems {
57        /// Collection vocabulary used for bounded diagnostics.
58        kind: &'static str,
59        /// Actual item count.
60        len: usize,
61        /// Maximum admitted item count.
62        max: usize,
63    },
64
65    /// One definition, assignment, or removal key occurs more than once.
66    #[error("schema contract contains a duplicate source key")]
67    DuplicateSourceKey,
68
69    /// One definition collides with an explicit removal.
70    #[error("schema contract defines and removes the same source key")]
71    DefinitionRemovalConflict,
72
73    /// Two definitions in one namespace use the same current name.
74    #[error("schema contract contains a duplicate current name")]
75    DuplicateName,
76
77    /// A definition refers to an absent key in its local closure.
78    #[error("schema contract contains an unresolved local reference")]
79    InvalidLocalReference,
80
81    /// One inline field-type contract exceeds the maintained depth bound.
82    #[error("schema field type exceeds its inline depth bound")]
83    FieldTypeDepthExceeded,
84
85    /// An enum literal names a non-enum type or an absent local variant.
86    #[error("schema contract contains an invalid enum literal reference")]
87    InvalidEnumLiteral,
88
89    /// A relation's source and target field contracts differ.
90    #[error("schema relation source and target field types differ")]
91    RelationTypeMismatch,
92
93    /// One explicit removal deletes a definition still referenced by the proposal.
94    #[error("schema contract removes a referenced definition")]
95    RemovedReference,
96
97    /// One entity does not have exactly one target-store assignment.
98    #[error("schema proposal entity routing is incomplete")]
99    MissingEntityStoreAssignment,
100
101    /// A field combines incompatible nullability, insert, type, or management policy.
102    #[error("schema field policy is invalid")]
103    InvalidFieldPolicy,
104
105    /// A field type carries an impossible width, scale, or bound.
106    #[error("schema field type is invalid")]
107    InvalidFieldType,
108
109    /// A field default literal does not fit the exact declared field contract.
110    #[error("schema field default does not match its exact field type")]
111    LiteralTypeMismatch,
112
113    /// One ordered field/reference list is empty or contains duplicates.
114    #[error("schema contract contains an invalid ordered reference list")]
115    InvalidReferenceList,
116
117    /// A literal is malformed or non-canonical.
118    #[error("schema proposal literal is malformed")]
119    InvalidLiteral,
120
121    /// A source check expression is malformed.
122    #[error("schema source check expression is malformed")]
123    InvalidExpression,
124
125    /// A targeted durable-rule operation or its operand ordering is invalid.
126    #[error("schema targeted durable-rule operation is invalid")]
127    InvalidRuleOperation,
128
129    /// A targeted durable rule cannot select the declared nominal value.
130    #[error("schema targeted durable-rule target is invalid")]
131    InvalidRuleTarget,
132
133    /// The proposal contract version is not the maintained current version.
134    #[error("schema proposal contract version is unsupported")]
135    UnsupportedVersion {
136        /// Version carried by the proposal.
137        found: u16,
138        /// Sole current version understood by this crate.
139        supported: u16,
140    },
141
142    /// The proposal requires a capability not understood by this contract.
143    #[error("schema proposal requires an unsupported capability")]
144    UnsupportedCapability,
145
146    /// A decoded proposal is structurally valid but not canonically ordered.
147    #[error("schema proposal is not canonically ordered")]
148    NonCanonical,
149
150    /// Encoded bytes exceed the relevant transport limit.
151    #[error("encoded schema contract exceeds its byte limit")]
152    EncodedTooLarge {
153        /// Actual byte length.
154        len: usize,
155        /// Maximum admitted byte length.
156        max: usize,
157    },
158
159    /// Serialization failed.
160    #[error("schema contract encoding failed")]
161    Encode,
162
163    /// Bounded current-form decoding failed.
164    #[error("schema contract decoding failed")]
165    Decode,
166}