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 current name.
45 #[error("schema contract contains a duplicate current name")]
46 DuplicateName,
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 /// One inline field-type contract exceeds the maintained depth bound.
53 #[error("schema field type exceeds its inline depth bound")]
54 FieldTypeDepthExceeded,
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 /// A targeted durable-rule operation or its operand ordering is invalid.
97 #[error("schema targeted durable-rule operation is invalid")]
98 InvalidRuleOperation,
99
100 /// A targeted durable rule cannot select the declared nominal value.
101 #[error("schema targeted durable-rule target is invalid")]
102 InvalidRuleTarget,
103
104 /// The proposal contract version is not the maintained current version.
105 #[error("schema proposal contract version is unsupported")]
106 UnsupportedVersion {
107 /// Version carried by the proposal.
108 found: u16,
109 /// Sole current version understood by this crate.
110 supported: u16,
111 },
112
113 /// The proposal requires a capability not understood by this contract.
114 #[error("schema proposal requires an unsupported capability")]
115 UnsupportedCapability,
116
117 /// A decoded proposal is structurally valid but not canonically ordered.
118 #[error("schema proposal is not canonically ordered")]
119 NonCanonical,
120
121 /// Encoded bytes exceed the relevant transport limit.
122 #[error("encoded schema contract exceeds its byte limit")]
123 EncodedTooLarge {
124 /// Actual byte length.
125 len: usize,
126 /// Maximum admitted byte length.
127 max: usize,
128 },
129
130 /// Serialization failed.
131 #[error("schema contract encoding failed")]
132 Encode,
133
134 /// Bounded current-form decoding failed.
135 #[error("schema contract decoding failed")]
136 Decode,
137}