Skip to main content

scientific_workflow/study/
error.rs

1//! Study composition and preflight failures.
2
3use std::path::{Path, PathBuf};
4
5use thiserror::Error;
6
7use crate::config::ConfigError;
8use crate::state::StateError;
9use crate::task::ExecutionUnitCatalogError;
10
11/// A failure while compiling complete declared intent into an immutable study.
12#[derive(Debug, Error)]
13#[non_exhaustive]
14pub enum StudyError {
15    /// Config could not load or validate project declarations.
16    #[error("failed to load project declarations")]
17    Config(#[from] ConfigError),
18
19    /// State rejected one centrally parsed named state-schema document.
20    #[error("failed to validate state schema `{state}` from `{path}`")]
21    State {
22        /// Semantic state key declared by the study manifest.
23        state: String,
24        /// Canonical source document path retained by Config.
25        path: PathBuf,
26        /// Original State semantic-validation failure.
27        #[source]
28        source: StateError,
29    },
30
31    /// State rejected a static schema document supplied by a linked provider.
32    #[error("failed to validate standard state-schema provider `{provider}`")]
33    ProvidedState {
34        /// Stable provider identity declared by the receiving execution unit.
35        provider: String,
36        /// Original State semantic-validation failure.
37        #[source]
38        source: StateError,
39    },
40
41    /// One standard provider declaration is invalid or conflicts with another.
42    #[error("invalid standard state-schema provider `{provider}`: {reason}")]
43    InvalidStateSchemaProvider {
44        /// Rejected stable provider identity.
45        provider: String,
46        /// Stable explanation of the rejected declaration.
47        reason: String,
48    },
49
50    /// Compiled execution-unit registrations are invalid or ambiguous.
51    #[error("invalid compiled execution-unit registration: {reason}")]
52    InvalidExecutionUnitRegistration {
53        /// Stable explanation of the invalid or duplicate registration.
54        reason: String,
55    },
56
57    /// A manifest task references no compiled execution unit.
58    #[error("phase `{phase}` references unregistered execution unit `{execution_unit}`")]
59    UnknownExecutionUnit {
60        /// Phase containing the unresolved reference.
61        phase: String,
62        /// Stable execution-unit key requested by the manifest.
63        execution_unit: String,
64    },
65
66    /// A task omitted its state and its execution unit supplies no standard provider.
67    #[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 containing the unresolved invocation.
72        phase: String,
73        /// Registered execution-unit key with no schema source.
74        execution_unit: String,
75    },
76
77    /// Typed constants or observation-plan binding failed during execution-unit preflight.
78    #[error(
79        "execution unit `{execution_unit}` failed preflight for resolved parameters {ordinal} in phase `{phase}`"
80    )]
81    ExecutionUnitPreflight {
82        /// Phase containing the rejected invocation.
83        phase: String,
84        /// Stable compiled execution-unit key.
85        execution_unit: String,
86        /// Deterministic parameter expansion ordinal.
87        ordinal: u64,
88        /// Original config, observation, or execution-unit declaration error.
89        #[source]
90        source: Box<dyn std::error::Error + Send + Sync + 'static>,
91    },
92
93    /// The total expanded task count cannot be represented by stable ordinals.
94    #[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}