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