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    /// Compiled execution-unit registrations are invalid or ambiguous.
32    #[error("invalid compiled execution-unit registration: {reason}")]
33    InvalidExecutionUnitRegistration {
34        /// Stable explanation of the invalid or duplicate registration.
35        reason: String,
36    },
37
38    /// A manifest task references no compiled execution unit.
39    #[error("phase `{phase}` references unregistered execution unit `{execution_unit}`")]
40    UnknownExecutionUnit {
41        /// Phase containing the unresolved reference.
42        phase: String,
43        /// Stable execution-unit key requested by the manifest.
44        execution_unit: String,
45    },
46
47    /// Typed constants or observation-plan binding failed during execution-unit preflight.
48    #[error(
49        "execution unit `{execution_unit}` failed preflight for resolved parameters {ordinal} in phase `{phase}`"
50    )]
51    ExecutionUnitPreflight {
52        /// Phase containing the rejected invocation.
53        phase: String,
54        /// Stable compiled execution-unit key.
55        execution_unit: String,
56        /// Deterministic parameter expansion ordinal.
57        ordinal: u64,
58        /// Original config, observation, or execution-unit declaration error.
59        #[source]
60        source: Box<dyn std::error::Error + Send + Sync + 'static>,
61    },
62
63    /// The total expanded task count cannot be represented by stable ordinals.
64    #[error("the study contains more expanded task invocations than can be identified")]
65    TaskIdentityOverflow,
66}
67
68impl From<ExecutionUnitCatalogError> for StudyError {
69    fn from(source: ExecutionUnitCatalogError) -> Self {
70        Self::InvalidExecutionUnitRegistration {
71            reason: source.to_string(),
72        }
73    }
74}
75
76impl StudyError {
77    pub(crate) fn state_schema(state: &str, path: &Path, source: StateError) -> Self {
78        Self::State {
79            state: state.to_owned(),
80            path: path.to_path_buf(),
81            source,
82        }
83    }
84
85    pub(crate) fn execution_unit_preflight(
86        phase: &str,
87        execution_unit: &str,
88        ordinal: u64,
89        source: Box<dyn std::error::Error + Send + Sync + 'static>,
90    ) -> Self {
91        Self::ExecutionUnitPreflight {
92            phase: phase.to_owned(),
93            execution_unit: execution_unit.to_owned(),
94            ordinal,
95            source,
96        }
97    }
98}