-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy patherror.rs
More file actions
247 lines (231 loc) · 7.93 KB
/
Copy patherror.rs
File metadata and controls
247 lines (231 loc) · 7.93 KB
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
use std::fmt;
use crate::contract::ContractViolation;
use crate::dist::FilteredSampleError;
use crate::ir::Segment;
use crate::replay::ReplayError;
/// Structured failure from a fallible pass execution.
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum PassError {
/// A contract-aware sampling pass could not produce an admissible candidate.
ConstraintSampling {
pass_name: String,
address: String,
reason: FilteredSampleError,
},
/// A pass that requires reference data was run without it.
MissingRefData { pass_name: String },
/// A pass requires an allele assignment that is absent.
MissingAssignment { pass_name: String, segment: Segment },
/// The IR references an allele id absent from the supplied reference data.
MissingAllele {
pass_name: String,
segment: Segment,
allele_id: u32,
},
/// A distribution emitted a value outside the pass's valid domain.
InvalidDistributionOutput {
pass_name: String,
address: String,
value: i64,
reason: String,
},
/// The current IR and plan state are inconsistent for this pass.
InvalidPlanState { pass_name: String, reason: String },
/// A pass produced a post-state that violates active contracts.
ContractViolation {
pass_name: String,
violations: Vec<ContractViolation>,
},
/// Trace-injected replay (Option B) could not consume the next
/// expected record. The wrapped [`ReplayError`] carries the
/// position, expected address, value-kind details. Surfaced at
/// the pass that hit the mismatch so callers can diagnose which
/// part of the plan went off the rails.
Replay {
pass_name: String,
reason: ReplayError,
},
}
impl PassError {
pub fn constraint_sampling(
pass_name: impl Into<String>,
address: impl Into<String>,
reason: FilteredSampleError,
) -> Self {
Self::ConstraintSampling {
pass_name: pass_name.into(),
address: address.into(),
reason,
}
}
pub fn missing_refdata(pass_name: impl Into<String>) -> Self {
Self::MissingRefData {
pass_name: pass_name.into(),
}
}
pub fn missing_assignment(pass_name: impl Into<String>, segment: Segment) -> Self {
Self::MissingAssignment {
pass_name: pass_name.into(),
segment,
}
}
pub fn missing_allele(pass_name: impl Into<String>, segment: Segment, allele_id: u32) -> Self {
Self::MissingAllele {
pass_name: pass_name.into(),
segment,
allele_id,
}
}
pub fn invalid_distribution_output(
pass_name: impl Into<String>,
address: impl Into<String>,
value: i64,
reason: impl Into<String>,
) -> Self {
Self::InvalidDistributionOutput {
pass_name: pass_name.into(),
address: address.into(),
value,
reason: reason.into(),
}
}
pub fn invalid_plan_state(pass_name: impl Into<String>, reason: impl Into<String>) -> Self {
Self::InvalidPlanState {
pass_name: pass_name.into(),
reason: reason.into(),
}
}
pub fn contract_violation(
pass_name: impl Into<String>,
violations: Vec<ContractViolation>,
) -> Self {
Self::ContractViolation {
pass_name: pass_name.into(),
violations,
}
}
pub fn replay(pass_name: impl Into<String>, reason: ReplayError) -> Self {
Self::Replay {
pass_name: pass_name.into(),
reason,
}
}
pub fn pass_name(&self) -> &str {
match self {
Self::ConstraintSampling { pass_name, .. } => pass_name,
Self::MissingRefData { pass_name } => pass_name,
Self::MissingAssignment { pass_name, .. } => pass_name,
Self::MissingAllele { pass_name, .. } => pass_name,
Self::InvalidDistributionOutput { pass_name, .. } => pass_name,
Self::InvalidPlanState { pass_name, .. } => pass_name,
Self::ContractViolation { pass_name, .. } => pass_name,
Self::Replay { pass_name, .. } => pass_name,
}
}
pub fn address(&self) -> &str {
match self {
Self::ConstraintSampling { address, .. } => address,
Self::InvalidDistributionOutput { address, .. } => address,
Self::MissingRefData { .. }
| Self::MissingAssignment { .. }
| Self::MissingAllele { .. }
| Self::InvalidPlanState { .. }
| Self::ContractViolation { .. }
| Self::Replay { .. } => "",
}
}
/// The replay-specific failure reason, if this is a
/// [`PassError::Replay`].
pub fn replay_reason(&self) -> Option<&ReplayError> {
match self {
Self::Replay { reason, .. } => Some(reason),
_ => None,
}
}
pub fn constraint_reason(&self) -> Option<FilteredSampleError> {
match self {
Self::ConstraintSampling { reason, .. } => Some(*reason),
_ => None,
}
}
}
impl fmt::Display for PassError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::ConstraintSampling {
pass_name,
address,
reason,
} => {
let detail = match reason {
FilteredSampleError::SupportUnavailable => {
"distribution support is not enumerable"
}
FilteredSampleError::EmptyAdmissibleSupport => {
"no admissible candidates remain after contract filtering"
}
FilteredSampleError::InvalidFilteredSupport => {
"filtered support has invalid weights"
}
};
write!(
f,
"{} failed strict constrained sampling at {}: {}",
pass_name, address, detail
)
}
Self::MissingRefData { pass_name } => {
write!(
f,
"{} requires reference data in strict execution",
pass_name
)
}
Self::MissingAssignment { pass_name, segment } => write!(
f,
"{} requires a {:?} allele assignment before execution",
pass_name, segment
),
Self::MissingAllele {
pass_name,
segment,
allele_id,
} => write!(
f,
"{} could not resolve {:?} allele id {} in reference data",
pass_name, segment, allele_id
),
Self::InvalidDistributionOutput {
pass_name,
address,
value,
reason,
} => write!(
f,
"{} received invalid distribution output at {}: {} ({})",
pass_name, address, value, reason
),
Self::InvalidPlanState { pass_name, reason } => {
write!(
f,
"{} cannot execute in current plan state: {}",
pass_name, reason
)
}
Self::ContractViolation {
pass_name,
violations,
} => {
write!(f, "{} produced a contract-invalid state", pass_name)?;
for violation in violations {
write!(f, "; {}: {}", violation.contract_name, violation.reason)?;
}
Ok(())
}
Self::Replay { pass_name, reason } => {
write!(f, "{}: {}", pass_name, reason)
}
}
}
}
impl std::error::Error for PassError {}