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    /// A declared entity source version is zero.
134    #[error("schema entity source version must be positive")]
135    InvalidEntityVersion,
136
137    /// A coordinated source migration is empty or otherwise malformed.
138    #[error("schema migration plan is invalid")]
139    InvalidMigrationPlan,
140
141    /// One migration selector does not resolve in the current proposal.
142    #[error("schema migration target reference is invalid")]
143    InvalidMigrationReference,
144
145    /// More than one migration operation claims the same predecessor object.
146    #[error("schema migration contains a duplicate source selector")]
147    DuplicateMigrationSource,
148
149    /// More than one migration operation claims the same current target.
150    #[error("schema migration contains a duplicate target selector")]
151    DuplicateMigrationTarget,
152
153    /// An entity migration does not describe the immediate predecessor.
154    #[error("schema migration entity versions are not contiguous")]
155    MigrationVersionGap,
156
157    /// A migration transform is outside the closed current vocabulary.
158    #[error("schema migration transform is invalid")]
159    InvalidMigrationTransform,
160
161    /// The migration program version is not the maintained current version.
162    #[error("schema migration program version is unsupported")]
163    UnsupportedMigrationProgramVersion {
164        /// Version carried by the plan.
165        found: u16,
166        /// Sole current version understood by this crate.
167        supported: u16,
168    },
169
170    /// The proposal contract version is not the maintained current version.
171    #[error("schema proposal contract version is unsupported")]
172    UnsupportedVersion {
173        /// Version carried by the proposal.
174        found: u16,
175        /// Sole current version understood by this crate.
176        supported: u16,
177    },
178
179    /// The proposal requires a capability not understood by this contract.
180    #[error("schema proposal requires an unsupported capability")]
181    UnsupportedCapability,
182
183    /// A decoded proposal is structurally valid but not canonically ordered.
184    #[error("schema proposal is not canonically ordered")]
185    NonCanonical,
186
187    /// Encoded bytes exceed the relevant transport limit.
188    #[error("encoded schema contract exceeds its byte limit")]
189    EncodedTooLarge {
190        /// Actual byte length.
191        len: usize,
192        /// Maximum admitted byte length.
193        max: usize,
194    },
195
196    /// Serialization failed.
197    #[error("schema contract encoding failed")]
198    Encode,
199
200    /// Bounded current-form decoding failed.
201    #[error("schema contract decoding failed")]
202    Decode,
203}