Skip to main content

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