scientific_workflow/runtime/error.rs
1//! Active runtime failures.
2
3use std::path::PathBuf;
4use std::time::Duration;
5
6use thiserror::Error;
7
8/// A failure after an immutable study passed preflight.
9#[derive(Debug, Error)]
10#[non_exhaustive]
11pub enum RuntimeError {
12 /// Runtime could not create the required study-wide compute pool.
13 #[error("failed to create the Workflow compute pool with {threads} threads")]
14 ComputePool {
15 /// Exact worker count authored in `wf_configs/study.json`.
16 threads: usize,
17 /// Rayon pool-construction failure.
18 #[source]
19 source: rayon::ThreadPoolBuildError,
20 },
21
22 /// Interactive UI requested cooperative cancellation of the execution.
23 #[error("workflow execution was cancelled by the user")]
24 ExecutionCancelled,
25
26 /// The automatically selected presentation adapter could not start,
27 /// publish lifecycle output, poll input, draw, or finish cleanly.
28 #[error("workflow presentation failed: {source}")]
29 Presentation {
30 /// Original presentation failure.
31 #[source]
32 source: Box<dyn std::error::Error + Send + Sync + 'static>,
33 },
34
35 /// Runtime could not create an inferred execution or replicate scope.
36 #[error("failed to create inferred output scope `{path}`")]
37 OutputScope {
38 /// Intended output location.
39 path: PathBuf,
40 /// Underlying filesystem failure.
41 #[source]
42 source: std::io::Error,
43 },
44
45 /// An execution-unit or program invocation returned an application, process, state,
46 /// observation, or persistence error.
47 #[error("task `{task}` failed: {source}")]
48 Task {
49 /// Inferred task identity.
50 task: String,
51 /// Original task failure.
52 #[source]
53 source: Box<dyn std::error::Error + Send + Sync + 'static>,
54 },
55
56 /// A task invocation panicked. Runtime fails any active member recording
57 /// before reporting this stable task identity.
58 #[error("task `{task}` panicked")]
59 TaskPanicked {
60 /// Inferred task identity.
61 task: String,
62 },
63
64 /// A task exceeded its timeout; execution units stop cooperatively while external
65 /// programs are terminated by Runtime.
66 #[error("task `{task}` exceeded its timeout of {timeout:?}")]
67 TaskTimedOut {
68 /// Inferred task identity.
69 task: String,
70 /// Effective timeout.
71 timeout: Duration,
72 },
73
74 /// A running task stopped because Runtime cancelled it. Execution units stop
75 /// cooperatively while external programs are terminated.
76 #[error("task `{task}` was cancelled")]
77 TaskCancelled {
78 /// Inferred task identity.
79 task: String,
80 },
81
82 /// A phase exceeded its timeout. Its active execution-unit tasks stop cooperatively
83 /// and its active external programs are terminated.
84 #[error("phase `{phase}` exceeded its timeout of {timeout:?}")]
85 PhaseTimedOut {
86 /// Stable phase key.
87 phase: String,
88 /// Effective timeout.
89 timeout: Duration,
90 },
91
92 /// Runtime could not start an operating-system worker thread.
93 #[error("failed to start runtime worker for `{scope}`")]
94 StartWorker {
95 /// Task or replicate identity.
96 scope: String,
97 /// Thread creation failure.
98 #[source]
99 source: std::io::Error,
100 },
101
102 /// A replicate worker panicked.
103 #[error("replicate {index} panicked")]
104 ReplicatePanicked {
105 /// Zero-based replicate index.
106 index: u64,
107 },
108
109 /// A replicate failed under either failure policy.
110 #[error("replicate {index} failed: {source}")]
111 Replicate {
112 /// Zero-based failed replicate index.
113 index: u64,
114 /// Original runtime failure.
115 #[source]
116 source: Box<RuntimeError>,
117 },
118}
119
120impl RuntimeError {
121 pub(crate) fn presentation_boxed(
122 source: Box<dyn std::error::Error + Send + Sync + 'static>,
123 ) -> Self {
124 Self::Presentation { source }
125 }
126}