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    /// Timestamp text is invalid.
17    InvalidTimestamp,
18}
19
20impl Display for TypeParseError {
21    fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
22        formatter.write_str(match self {
23            Self::InvalidDate => "invalid date",
24            Self::InvalidDecimal => "invalid decimal",
25            Self::InvalidDuration => "invalid duration",
26            Self::InvalidTimestamp => "invalid timestamp",
27        })
28    }
29}
30
31/// Failure while constructing, validating, encoding, or decoding proposal data.
32#[derive(Clone, Debug, Eq, Error, PartialEq)]
33pub enum SchemaContractError {
34    /// A required bounded text identity is empty.
35    #[error("schema contract identity is empty")]
36    EmptyIdentity,
37
38    /// A bounded text identity exceeds its byte limit.
39    #[error("schema contract identity exceeds its byte limit")]
40    IdentityTooLong {
41        /// Actual byte length.
42        len: usize,
43        /// Maximum admitted byte length.
44        max: usize,
45    },
46
47    /// A source key contains a non-canonical byte.
48    #[error("schema source key contains a non-canonical byte")]
49    InvalidSourceKey,
50
51    /// One bounded collection exceeds its item limit.
52    #[error("schema contract collection exceeds its item limit")]
53    TooManyItems {
54        /// Collection vocabulary used for bounded diagnostics.
55        kind: &'static str,
56        /// Actual item count.
57        len: usize,
58        /// Maximum admitted item count.
59        max: usize,
60    },
61
62    /// One definition, assignment, or removal key occurs more than once.
63    #[error("schema contract contains a duplicate source key")]
64    DuplicateSourceKey,
65
66    /// One definition collides with an explicit removal.
67    #[error("schema contract defines and removes the same source key")]
68    DefinitionRemovalConflict,
69
70    /// Two definitions in one namespace use the same current name.
71    #[error("schema contract contains a duplicate current name")]
72    DuplicateName,
73
74    /// A definition refers to an absent key in its local closure.
75    #[error("schema contract contains an unresolved local reference")]
76    InvalidLocalReference,
77
78    /// One inline field-type contract exceeds the maintained depth bound.
79    #[error("schema field type exceeds its inline depth bound")]
80    FieldTypeDepthExceeded,
81
82    /// An enum literal names a non-enum type or an absent local variant.
83    #[error("schema contract contains an invalid enum literal reference")]
84    InvalidEnumLiteral,
85
86    /// A relation's source and target field contracts differ.
87    #[error("schema relation source and target field types differ")]
88    RelationTypeMismatch,
89
90    /// One explicit removal deletes a definition still referenced by the proposal.
91    #[error("schema contract removes a referenced definition")]
92    RemovedReference,
93
94    /// One entity does not have exactly one target-store assignment.
95    #[error("schema proposal entity routing is incomplete")]
96    MissingEntityStoreAssignment,
97
98    /// A field combines incompatible nullability, insert, type, or management policy.
99    #[error("schema field policy is invalid")]
100    InvalidFieldPolicy,
101
102    /// A field type carries an impossible width, scale, or bound.
103    #[error("schema field type is invalid")]
104    InvalidFieldType,
105
106    /// A field default literal does not fit the exact declared field contract.
107    #[error("schema field default does not match its exact field type")]
108    LiteralTypeMismatch,
109
110    /// One ordered field/reference list is empty or contains duplicates.
111    #[error("schema contract contains an invalid ordered reference list")]
112    InvalidReferenceList,
113
114    /// A literal is malformed or non-canonical.
115    #[error("schema proposal literal is malformed")]
116    InvalidLiteral,
117
118    /// A source check expression is malformed.
119    #[error("schema source check expression is malformed")]
120    InvalidExpression,
121
122    /// A targeted durable-rule operation or its operand ordering is invalid.
123    #[error("schema targeted durable-rule operation is invalid")]
124    InvalidRuleOperation,
125
126    /// A targeted durable rule cannot select the declared nominal value.
127    #[error("schema targeted durable-rule target is invalid")]
128    InvalidRuleTarget,
129
130    /// A declared entity source version is zero.
131    #[error("schema entity source version must be positive")]
132    InvalidEntityVersion,
133
134    /// A coordinated source migration is empty or otherwise malformed.
135    #[error("schema migration plan is invalid")]
136    InvalidMigrationPlan,
137
138    /// One migration selector does not resolve in the current proposal.
139    #[error("schema migration target reference is invalid")]
140    InvalidMigrationReference,
141
142    /// More than one migration operation claims the same predecessor object.
143    #[error("schema migration contains a duplicate source selector")]
144    DuplicateMigrationSource,
145
146    /// More than one migration operation claims the same current target.
147    #[error("schema migration contains a duplicate target selector")]
148    DuplicateMigrationTarget,
149
150    /// An entity migration does not describe the immediate predecessor.
151    #[error("schema migration entity versions are not contiguous")]
152    MigrationVersionGap,
153
154    /// A migration transform is outside the closed current vocabulary.
155    #[error("schema migration transform is invalid")]
156    InvalidMigrationTransform,
157
158    /// The migration program version is not the maintained current version.
159    #[error("schema migration program version is unsupported")]
160    UnsupportedMigrationProgramVersion {
161        /// Version carried by the plan.
162        found: u16,
163        /// Sole current version understood by this crate.
164        supported: u16,
165    },
166
167    /// The proposal contract version is not the maintained current version.
168    #[error("schema proposal contract version is unsupported")]
169    UnsupportedVersion {
170        /// Version carried by the proposal.
171        found: u16,
172        /// Sole current version understood by this crate.
173        supported: u16,
174    },
175
176    /// The proposal requires a capability not understood by this contract.
177    #[error("schema proposal requires an unsupported capability")]
178    UnsupportedCapability,
179
180    /// A decoded proposal is structurally valid but not canonically ordered.
181    #[error("schema proposal is not canonically ordered")]
182    NonCanonical,
183
184    /// Encoded bytes exceed the relevant transport limit.
185    #[error("encoded schema contract exceeds its byte limit")]
186    EncodedTooLarge {
187        /// Actual byte length.
188        len: usize,
189        /// Maximum admitted byte length.
190        max: usize,
191    },
192
193    /// Serialization failed.
194    #[error("schema contract encoding failed")]
195    Encode,
196
197    /// Bounded current-form decoding failed.
198    #[error("schema contract decoding failed")]
199    Decode,
200}