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 /// A skipped prerequisite has no matching, successfully completed source result.
13 #[error("cannot reuse phase `{phase}` from `{path}`: {reason}")]
14 Reuse {
15 /// Phase whose prerequisite outputs could not be imported.
16 phase: String,
17 /// Explicit source execution or task directory.
18 path: PathBuf,
19 /// Missing, incomplete, or incompatible source evidence.
20 reason: String,
21 },
22 /// The selected active Python environment lacks compatible Workflow tools.
23 #[error(
24 "Python prerequisites failed for `{interpreter}`: {reason}. Activate a Python 3.14+ environment with scientific-workflow[npy] 0.4.4 before launching Workflow"
25 )]
26 PythonPrerequisite {
27 /// Selected interpreter, inherited from the active environment.
28 interpreter: PathBuf,
29 /// Probe failure details, including missing imports or incompatible versions.
30 reason: String,
31 },
32 /// Runtime could not create the required study-wide compute pool.
33 #[error("failed to create the Workflow compute pool with {threads} threads")]
34 ComputePool {
35 /// Exact worker count authored in `wf_configs/study.json`.
36 threads: usize,
37 /// Rayon pool-construction failure.
38 #[source]
39 source: rayon::ThreadPoolBuildError,
40 },
41
42 /// Interactive UI requested cooperative cancellation of the execution.
43 #[error("workflow execution was cancelled by the user")]
44 ExecutionCancelled,
45
46 /// The automatically selected presentation adapter could not start,
47 /// publish lifecycle output, poll input, draw, or finish cleanly.
48 #[error("workflow presentation failed: {source}")]
49 Presentation {
50 /// Original presentation failure.
51 #[source]
52 source: Box<dyn std::error::Error + Send + Sync + 'static>,
53 },
54
55 /// Runtime could not create an inferred execution or replicate scope.
56 #[error("failed to create inferred output scope `{path}`")]
57 OutputScope {
58 /// Intended output location.
59 path: PathBuf,
60 /// Underlying filesystem failure.
61 #[source]
62 source: std::io::Error,
63 },
64
65 /// An execution-unit or program invocation returned an application, process, state,
66 /// observation, or persistence error.
67 #[error("task `{task}` failed: {source}")]
68 Task {
69 /// Inferred task identity.
70 task: String,
71 /// Original task failure.
72 #[source]
73 source: Box<dyn std::error::Error + Send + Sync + 'static>,
74 },
75
76 /// A task invocation panicked. Runtime fails any active member recording
77 /// before reporting this stable task identity.
78 #[error("task `{task}` panicked")]
79 TaskPanicked {
80 /// Inferred task identity.
81 task: String,
82 },
83
84 /// A task exceeded its timeout; execution units stop cooperatively while external
85 /// programs are terminated by Runtime.
86 #[error("task `{task}` exceeded its timeout of {timeout:?}")]
87 TaskTimedOut {
88 /// Inferred task identity.
89 task: String,
90 /// Effective timeout.
91 timeout: Duration,
92 },
93
94 /// A running task stopped because Runtime cancelled it. Execution units stop
95 /// cooperatively while external programs are terminated.
96 #[error("task `{task}` was cancelled")]
97 TaskCancelled {
98 /// Inferred task identity.
99 task: String,
100 },
101
102 /// A phase exceeded its timeout. Its active execution-unit tasks stop cooperatively
103 /// and its active external programs are terminated.
104 #[error("phase `{phase}` exceeded its timeout of {timeout:?}")]
105 PhaseTimedOut {
106 /// Stable phase key.
107 phase: String,
108 /// Effective timeout.
109 timeout: Duration,
110 },
111
112 /// Runtime could not start an operating-system worker thread.
113 #[error("failed to start runtime worker for `{scope}`")]
114 StartWorker {
115 /// Task or replicate identity.
116 scope: String,
117 /// Thread creation failure.
118 #[source]
119 source: std::io::Error,
120 },
121
122 /// A replicate worker panicked.
123 #[error("replicate {index} panicked")]
124 ReplicatePanicked {
125 /// Zero-based replicate index.
126 index: u64,
127 },
128
129 /// A replicate failed under either failure policy.
130 #[error("replicate {index} failed: {source}")]
131 Replicate {
132 /// Zero-based failed replicate index.
133 index: u64,
134 /// Original runtime failure.
135 #[source]
136 source: Box<RuntimeError>,
137 },
138}
139
140impl RuntimeError {
141 pub(crate) fn presentation_boxed(
142 source: Box<dyn std::error::Error + Send + Sync + 'static>,
143 ) -> Self {
144 Self::Presentation { source }
145 }
146}