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
//! Typed validation and binding errors for mutation programs.
use std::fmt;
/// A typed validation, binding, or interpretation failure for a mutation program.
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum MutationProgramError {
/// A stable name, identifier, field, or storage name was empty.
EmptyName(&'static str),
/// A declared version must be non-zero.
ZeroVersion(&'static str),
/// A mutation program ID was not in canonical form.
InvalidProgramId,
/// An input path exceeded the portable segment limit.
PathTooDeep {
/// Observed segment count.
segments: usize,
/// Supported segment ceiling.
max: usize,
},
/// A portable expression or constant exceeded the nesting limit.
ExpressionTooDeep {
/// Observed nesting depth.
depth: usize,
/// Supported nesting ceiling.
max: usize,
},
/// A program declared too many operations.
TooManyOperations {
/// Observed operation count.
count: usize,
/// Supported operation ceiling.
max: usize,
},
/// A key, partition, or other bounded canonical value was too large.
ValueTooLarge {
/// Kind of bounded logical encoding.
kind: &'static str,
/// Observed encoded byte length.
len: usize,
/// Supported byte ceiling.
max: usize,
},
/// Two declarations used the same explicit ordinal.
DuplicateOrdinal {
/// Kind of ordered declaration.
kind: &'static str,
/// Repeated ordinal.
ordinal: u32,
},
/// Ordinals did not form a contiguous zero-based sequence.
NonContiguousOrdinal {
/// Kind of ordered declaration.
kind: &'static str,
/// Required next ordinal.
expected: u32,
/// Observed ordinal.
actual: u32,
},
/// Two declarations used the same stable name.
DuplicateName {
/// Kind of named declaration.
kind: &'static str,
/// Repeated name.
name: String,
},
/// A required expression evaluated as absent.
RequiredValueAbsent {
/// Stable expression or field description.
path: String,
},
/// `unset` appeared where the operation cannot represent it.
UnsetNotAllowed {
/// Field or expression position.
field: String,
},
/// A key component was null, absent, unset, or structurally invalid.
InvalidKeyValue {
/// Key component name.
field: String,
},
/// An operation shape was incompatible with its semantic kind.
InvalidOperation {
/// Stable operation identifier.
operation: String,
/// Validation reason.
reason: String,
},
/// Two operations could not deterministically become one final mutation.
AmbiguousMutation {
/// Affected logical model.
model: String,
/// Validation reason.
reason: String,
},
/// Returning selection was empty or ambiguous.
InvalidReturning {
/// Validation reason.
reason: String,
},
/// Conflict target was incomplete or unknown.
InvalidConflictTarget {
/// Validation reason.
reason: String,
},
/// Canonical JSON encoding failed.
CanonicalJson(String),
/// A bound input path was missing from the supplied input object.
MissingInput {
/// Missing input path.
path: String,
},
/// A binding or interpreter failed while adapting to projection IR.
Adapter(String),
}
impl fmt::Display for MutationProgramError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::EmptyName(kind) => write!(f, "{kind} must not be empty"),
Self::ZeroVersion(kind) => write!(f, "{kind} must be non-zero"),
Self::InvalidProgramId => write!(
f,
"mutation program ID must be `mp1:sha256:` followed by 64 lowercase hex digits"
),
Self::PathTooDeep { segments, max } => {
write!(f, "input path has {segments} segments; max is {max}")
}
Self::ExpressionTooDeep { depth, max } => {
write!(f, "expression nesting depth {depth} exceeds max {max}")
}
Self::TooManyOperations { count, max } => {
write!(f, "mutation program has {count} operations; max is {max}")
}
Self::ValueTooLarge { kind, len, max } => {
write!(f, "{kind} encoding is {len} bytes; max is {max}")
}
Self::DuplicateOrdinal { kind, ordinal } => {
write!(f, "duplicate {kind} ordinal {ordinal}")
}
Self::NonContiguousOrdinal {
kind,
expected,
actual,
} => write!(f, "{kind} ordinal expected {expected}, got {actual}"),
Self::DuplicateName { kind, name } => write!(f, "duplicate {kind} name `{name}`"),
Self::RequiredValueAbsent { path } => {
write!(f, "required value absent at `{path}`")
}
Self::UnsetNotAllowed { field } => {
write!(f, "unset is not allowed on field `{field}`")
}
Self::InvalidKeyValue { field } => write!(f, "invalid key value for `{field}`"),
Self::InvalidOperation { operation, reason } => {
write!(f, "invalid operation `{operation}`: {reason}")
}
Self::AmbiguousMutation { model, reason } => {
write!(f, "ambiguous mutation for model `{model}`: {reason}")
}
Self::InvalidReturning { reason } => write!(f, "invalid returning: {reason}"),
Self::InvalidConflictTarget { reason } => {
write!(f, "invalid conflict target: {reason}")
}
Self::CanonicalJson(error) => write!(f, "canonical JSON encoding failed: {error}"),
Self::MissingInput { path } => write!(f, "missing mutation input `{path}`"),
Self::Adapter(error) => write!(f, "mutation adapter error: {error}"),
}
}
}
impl std::error::Error for MutationProgramError {}
impl From<crate::projection::ProjectionProgramError> for MutationProgramError {
fn from(error: crate::projection::ProjectionProgramError) -> Self {
Self::Adapter(error.to_string())
}
}