scientific_workflow/study/
error.rs1use std::path::{Path, PathBuf};
4
5use thiserror::Error;
6
7use crate::config::ConfigError;
8use crate::state::StateError;
9use crate::task::ExecutionUnitCatalogError;
10
11#[derive(Debug, Error)]
13#[non_exhaustive]
14pub enum StudyError {
15 #[error("failed to load project declarations")]
17 Config(#[from] ConfigError),
18
19 #[error("failed to validate state schema `{state}` from `{path}`")]
21 State {
22 state: String,
24 path: PathBuf,
26 #[source]
28 source: StateError,
29 },
30
31 #[error("failed to validate standard state-schema provider `{provider}`")]
33 ProvidedState {
34 provider: String,
36 #[source]
38 source: StateError,
39 },
40
41 #[error("invalid standard state-schema provider `{provider}`: {reason}")]
43 InvalidStateSchemaProvider {
44 provider: String,
46 reason: String,
48 },
49
50 #[error("invalid compiled execution-unit registration: {reason}")]
52 InvalidExecutionUnitRegistration {
53 reason: String,
55 },
56
57 #[error("phase `{phase}` references unregistered execution unit `{execution_unit}`")]
59 UnknownExecutionUnit {
60 phase: String,
62 execution_unit: String,
64 },
65
66 #[error(
68 "execution unit `{execution_unit}` in phase `{phase}` requires an explicit project state because it has no standard state-schema provider"
69 )]
70 MissingStateSchema {
71 phase: String,
73 execution_unit: String,
75 },
76
77 #[error(
79 "execution unit `{execution_unit}` failed preflight for resolved parameters {ordinal} in phase `{phase}`"
80 )]
81 ExecutionUnitPreflight {
82 phase: String,
84 execution_unit: String,
86 ordinal: u64,
88 #[source]
90 source: Box<dyn std::error::Error + Send + Sync + 'static>,
91 },
92
93 #[error("the study contains more expanded task invocations than can be identified")]
95 TaskIdentityOverflow,
96}
97
98impl From<ExecutionUnitCatalogError> for StudyError {
99 fn from(source: ExecutionUnitCatalogError) -> Self {
100 Self::InvalidExecutionUnitRegistration {
101 reason: source.to_string(),
102 }
103 }
104}
105
106impl StudyError {
107 pub(crate) fn state_schema(state: &str, path: &Path, source: StateError) -> Self {
108 Self::State {
109 state: state.to_owned(),
110 path: path.to_path_buf(),
111 source,
112 }
113 }
114
115 pub(crate) fn execution_unit_preflight(
116 phase: &str,
117 execution_unit: &str,
118 ordinal: u64,
119 source: Box<dyn std::error::Error + Send + Sync + 'static>,
120 ) -> Self {
121 Self::ExecutionUnitPreflight {
122 phase: phase.to_owned(),
123 execution_unit: execution_unit.to_owned(),
124 ordinal,
125 source,
126 }
127 }
128}