icydb_schema/error.rs
1//! Typed failures at the public proposal-contract boundary.
2
3use thiserror::Error;
4
5/// Failure while constructing, validating, encoding, or decoding proposal data.
6#[derive(Clone, Debug, Eq, Error, PartialEq)]
7pub enum SchemaContractError {
8 /// A required bounded text identity is empty.
9 #[error("schema contract identity is empty")]
10 EmptyIdentity,
11
12 /// A bounded text identity exceeds its byte limit.
13 #[error("schema contract identity exceeds its byte limit")]
14 IdentityTooLong {
15 /// Actual byte length.
16 len: usize,
17 /// Maximum admitted byte length.
18 max: usize,
19 },
20
21 /// A source key contains a non-canonical byte.
22 #[error("schema source key contains a non-canonical byte")]
23 InvalidSourceKey,
24
25 /// One bounded collection exceeds its item limit.
26 #[error("schema contract collection exceeds its item limit")]
27 TooManyItems {
28 /// Collection vocabulary used for bounded diagnostics.
29 kind: &'static str,
30 /// Actual item count.
31 len: usize,
32 /// Maximum admitted item count.
33 max: usize,
34 },
35
36 /// One definition, assignment, or removal key occurs more than once.
37 #[error("schema contract contains a duplicate source key")]
38 DuplicateSourceKey,
39
40 /// One definition collides with an explicit removal.
41 #[error("schema contract defines and removes the same source key")]
42 DefinitionRemovalConflict,
43
44 /// Two definitions in one namespace use the same editable name.
45 #[error("schema contract contains an editable-name collision")]
46 DuplicateEditableName,
47
48 /// A definition refers to an absent key in its local closure.
49 #[error("schema contract contains an unresolved local reference")]
50 InvalidLocalReference,
51
52 /// A named-type graph is recursive or exceeds the maintained depth bound.
53 #[error("schema contract contains an invalid named-type graph")]
54 InvalidNamedTypeGraph,
55
56 /// An enum literal names a non-enum type or an absent local variant.
57 #[error("schema contract contains an invalid enum literal reference")]
58 InvalidEnumLiteral,
59
60 /// A relation's source and target field contracts differ.
61 #[error("schema relation source and target field types differ")]
62 RelationTypeMismatch,
63
64 /// One explicit removal deletes a definition still referenced by the proposal.
65 #[error("schema contract removes a referenced definition")]
66 RemovedReference,
67
68 /// One entity does not have exactly one target-store assignment.
69 #[error("schema proposal entity routing is incomplete")]
70 MissingEntityStoreAssignment,
71
72 /// A field combines incompatible nullability, insert, type, or management policy.
73 #[error("schema field policy is invalid")]
74 InvalidFieldPolicy,
75
76 /// A field type carries an impossible width, scale, or bound.
77 #[error("schema field type is invalid")]
78 InvalidFieldType,
79
80 /// A field default literal does not fit the exact declared field contract.
81 #[error("schema field default does not match its exact field type")]
82 LiteralTypeMismatch,
83
84 /// One ordered field/reference list is empty or contains duplicates.
85 #[error("schema contract contains an invalid ordered reference list")]
86 InvalidReferenceList,
87
88 /// A literal is malformed or non-canonical.
89 #[error("schema proposal literal is malformed")]
90 InvalidLiteral,
91
92 /// A source check expression is malformed.
93 #[error("schema source check expression is malformed")]
94 InvalidExpression,
95
96 /// The proposal contract version is not the maintained current version.
97 #[error("schema proposal contract version is unsupported")]
98 UnsupportedVersion {
99 /// Version carried by the proposal.
100 found: u16,
101 /// Sole current version understood by this crate.
102 supported: u16,
103 },
104
105 /// The proposal requires a capability not understood by this contract.
106 #[error("schema proposal requires an unsupported capability")]
107 UnsupportedCapability,
108
109 /// A decoded proposal is structurally valid but not canonically ordered.
110 #[error("schema proposal is not canonically ordered")]
111 NonCanonical,
112
113 /// Encoded bytes exceed the relevant transport limit.
114 #[error("encoded schema contract exceeds its byte limit")]
115 EncodedTooLarge {
116 /// Actual byte length.
117 len: usize,
118 /// Maximum admitted byte length.
119 max: usize,
120 },
121
122 /// Serialization failed.
123 #[error("schema contract encoding failed")]
124 Encode,
125
126 /// Bounded current-form decoding failed.
127 #[error("schema contract decoding failed")]
128 Decode,
129}