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