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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
//! Errors produced while planning, scheduling, and rendering a study.
use std::io;
use std::path::PathBuf;
use std::time::Duration;
use thiserror::Error;
/// Failure while validating, executing, recording, or displaying a study.
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum StudyError {
/// A completed study record could not be encoded as JSON.
#[error("failed to serialize study record")]
SerializeStudyRecord {
/// Underlying Serde serialization failure.
#[source]
source: serde_json::Error,
},
/// A serialized study record could not be written durably.
#[error("failed to write study record `{path}`")]
WriteStudyRecord {
/// Destination study-record path.
path: PathBuf,
/// Underlying filesystem failure.
#[source]
source: io::Error,
},
/// A UTC timestamp required by a study record could not be formatted.
#[error("failed to format UTC timestamp while attempting to {operation}")]
StudyRecordTimestamp {
/// Record operation that requested the timestamp.
operation: &'static str,
/// Underlying time-formatting failure.
#[source]
source: time::error::Format,
},
/// A study plan could not be encoded as JSON.
#[error("failed to serialize study plan")]
SerializeStudyPlan {
/// Underlying Serde serialization failure.
#[source]
source: serde_json::Error,
},
/// A serialized study plan could not be written durably.
#[error("failed to write study plan `{path}`")]
WriteStudyPlan {
/// Destination study-plan path.
path: PathBuf,
/// Underlying filesystem failure.
#[source]
source: io::Error,
},
/// A plan destination already contains a different immutable declaration.
#[error("study plan destination `{path}` already contains different data")]
StudyPlanConflict {
/// Path containing the conflicting plan.
path: PathBuf,
},
/// A phase failed after producing a durable partial study summary.
#[error("study phase execution failed: {source}")]
PhaseExecutionFailed {
/// Summary and record containing all completed phase outcomes.
summary: super::StudySummary,
/// Original phase execution failure.
#[source]
source: Box<StudyError>,
},
/// Another study currently owns the process-wide terminal renderer.
#[error("another study renderer already owns the process terminal")]
TerminalAlreadyOwned,
/// A phase was declared without tasks.
#[error("phase {phase} must contain at least one task")]
EmptyPhase {
/// Invalid phase identity.
phase: u64,
},
/// A study was declared without phases.
#[error("a study must contain at least one phase")]
EmptyPhaseSet,
/// A phase label is empty or whitespace-only.
#[error("phase {phase} must have a nonempty label")]
InvalidPhaseLabel {
/// Invalid phase identity.
phase: u64,
},
/// A phase declares a zero active-task limit.
#[error("phase {phase} max_active_tasks must be greater than zero")]
InvalidPhaseWorkloadLimit {
/// Invalid phase identity.
phase: u64,
},
/// A phase declares a zero prepared-task queue capacity.
#[error("phase {phase} prepared_task_queue_capacity must be greater than zero")]
InvalidPhaseQueueCapacity {
/// Invalid phase identity.
phase: u64,
},
/// A phase timing setting is zero or cannot be represented internally.
#[error("phase {phase} timing setting `{setting}` must be nonzero and representable")]
InvalidPhaseTiming {
/// Invalid phase identity.
phase: u64,
/// Name of the rejected timing setting.
setting: &'static str,
},
/// Two phases have the same stable identity.
#[error("phase ID {phase} appears more than once")]
DuplicatePhaseId {
/// Repeated phase identity.
phase: u64,
},
/// A phase depends on an undeclared phase.
#[error("phase {phase} depends on unknown phase {dependency}")]
UnknownPhaseDependency {
/// Depending phase identity.
phase: u64,
/// Missing dependency identity.
dependency: u64,
},
/// The declared phase dependency graph is cyclic.
#[error("phase dependency graph contains a cycle involving phase {phase}")]
PhaseDependencyCycle {
/// One phase involved in the cycle.
phase: u64,
},
/// Execution selected a phase that is not declared.
#[error("selected phase {phase} is not registered")]
UnknownSelectedPhase {
/// Missing selected phase identity.
phase: u64,
},
/// Execution omitted a required dependency of a selected phase.
#[error("selected phase {phase} requires unsatisfied phase {dependency}")]
UnsatisfiedPhaseDependency {
/// Selected phase identity.
phase: u64,
/// Omitted dependency identity.
dependency: u64,
},
/// Interactive confirmation input ended before another phase could start.
#[error("confirmation input ended after phase {phase} before the next phase could start")]
PhaseConfirmationEof {
/// Last completed phase identity.
phase: u64,
},
/// Interactive confirmation input could not be read.
#[error("failed to read confirmation after phase {phase}")]
PhaseConfirmationInput {
/// Last completed phase identity.
phase: u64,
/// Underlying input failure.
#[source]
source: io::Error,
},
/// An executable task declaration has no workload.
#[error("task `{task}` has no workload")]
MissingTaskWorkload {
/// Phase-qualified task identity.
task: String,
},
/// An application-owned task workload returned an error.
#[error("task `{task}` failed: {source}")]
TaskWorkload {
/// Phase-qualified task identity.
task: String,
/// Application-owned workload failure.
#[source]
source: Box<dyn std::error::Error + Send + Sync + 'static>,
},
/// A task did not stop cooperatively before its timeout.
#[error("task `{task}` exceeded its timeout of {timeout:?}")]
TaskTimedOut {
/// Phase-qualified task identity.
task: String,
/// Configured task timeout.
timeout: Duration,
},
/// A phase did not stop cooperatively before its deadline.
#[error("phase {phase} exceeded its deadline of {deadline_after:?}")]
PhaseDeadlineExceeded {
/// Expired phase identity.
phase: u64,
/// Configured phase deadline relative to its start.
deadline_after: Duration,
},
/// A scheduler worker thread panicked.
#[error("a study scheduler worker panicked")]
SchedulerPanicked,
/// Study execution was cancelled cooperatively.
#[error("study execution was cancelled")]
Cancelled,
/// A task ID is empty or whitespace-only.
#[error("phase {phase} contains an empty task ID")]
InvalidTaskId {
/// Phase containing the invalid task.
phase: u64,
},
/// A task category is empty or whitespace-only.
#[error("task `{task}` must have a nonempty category")]
InvalidTaskCategory {
/// Phase-qualified invalid task identity.
task: String,
},
/// A phase repeats a task ID.
#[error("phase {phase} repeats task ID `{task}`")]
DuplicateTaskId {
/// Phase containing the duplicate.
phase: u64,
/// Repeated phase-local task ID.
task: String,
},
/// A task selector matched no declared task.
#[error("task selector `{selector}` matched no task")]
TaskNotFound {
/// Unmatched selector text.
selector: String,
},
/// An unqualified selector matched more than one task.
#[error("task selector `{selector}` is ambiguous between `{first}` and `{second}`")]
TaskSelectorAmbiguous {
/// Ambiguous selector text.
selector: String,
/// First matching phase-qualified task identity.
first: String,
/// Second matching phase-qualified task identity.
second: String,
},
/// A task does not contain requested metadata.
#[error("task `{task}` does not contain metadata `{key}`")]
UnknownTaskMetadata {
/// Phase-qualified task identity.
task: String,
/// Missing metadata key.
key: String,
},
/// Task metadata could not be decoded as the requested type.
#[error("task `{task}` metadata `{key}` could not be decoded")]
DecodeTaskMetadata {
/// Phase-qualified task identity.
task: String,
/// Metadata key being decoded.
key: String,
/// Underlying Serde conversion failure.
#[source]
source: serde_json::Error,
},
/// A progress operation referenced an unregistered task.
#[error("task `{task}` is not registered with this renderer")]
UnknownTask {
/// Unregistered phase-qualified task identity.
task: String,
},
/// A progress operation is incompatible with the task's declared mode.
#[error("task `{task}` is declared as {actual}, not {requested}")]
TaskModeMismatch {
/// Phase-qualified task identity.
task: String,
/// Mode required by the attempted operation.
requested: &'static str,
/// Mode declared by the task.
actual: &'static str,
},
/// A task was started after already leaving its pending state.
#[error("task `{identity}` has already started or reached a terminal status")]
TaskAlreadyStarted {
/// Phase-qualified task identity.
identity: String,
},
/// Initial progress is greater than the declared target iteration.
#[error("task `{identity}` starts at iteration {initial}, beyond target {target}")]
InitialIterationBeyondTarget {
/// Phase-qualified task identity.
identity: String,
/// Rejected initial iteration.
initial: u64,
/// Declared target iteration.
target: u64,
},
/// A task attempted to report a lower iteration than previously observed.
#[error("task `{identity}` cannot move progress from iteration {current} back to {attempted}")]
IterationRegressed {
/// Phase-qualified task identity.
identity: String,
/// Last accepted iteration.
current: u64,
/// Rejected lower iteration.
attempted: u64,
},
/// A task reported progress beyond its target iteration.
#[error("task `{identity}` reported iteration {iteration}, beyond target {target}")]
IterationBeyondTarget {
/// Phase-qualified task identity.
identity: String,
/// Rejected reported iteration.
iteration: u64,
/// Declared target iteration.
target: u64,
},
/// A task reported completion before reaching its target iteration.
#[error("task `{identity}` completed at iteration {current}, before target {target}")]
TargetIterationNotReached {
/// Phase-qualified task identity.
identity: String,
/// Last accepted iteration.
current: u64,
/// Declared target iteration.
target: u64,
},
/// The renderer thread could not be created.
#[error("failed to start the study renderer")]
StartRenderer {
/// Underlying thread-creation failure.
#[source]
source: io::Error,
},
/// The process terminal could not be prepared or restored.
#[error("failed to {operation} for the study display")]
TerminalSetup {
/// Stable terminal operation description.
operation: &'static str,
/// Underlying terminal IO failure.
#[source]
source: io::Error,
},
/// The renderer stopped accepting progress commands unexpectedly.
#[error("the study renderer is no longer available")]
RendererUnavailable,
/// The renderer thread panicked.
#[error("the study renderer panicked")]
RendererPanicked,
/// A success summary was requested while non-success task states remain.
#[error(
"cannot report success with {pending} pending, {running} running, and {failed} failed tasks"
)]
IncompleteProgress {
/// Number of tasks that never started.
pending: u64,
/// Number of tasks still running.
running: u64,
/// Number of failed tasks.
failed: u64,
},
}
impl StudyError {
/// Returns the durable partial summary attached to a phase execution failure.
pub fn study_summary(&self) -> Option<&super::StudySummary> {
match self {
Self::PhaseExecutionFailed { summary, .. } => Some(summary),
_ => None,
}
}
/// Returns the original cause attached to a phase execution failure.
pub fn execution_cause(&self) -> Option<&StudyError> {
match self {
Self::PhaseExecutionFailed { source, .. } => Some(source),
_ => None,
}
}
}