Skip to main content

scientific_workflow/study/
error.rs

1//! Study composition and preflight failures.
2
3use thiserror::Error;
4
5use crate::config::advanced::ConfigError;
6use crate::state::advanced::StateError;
7use crate::task::advanced::ModelCatalogError;
8
9/// A failure while compiling complete declared intent into an immutable study.
10#[derive(Debug, Error)]
11#[non_exhaustive]
12pub enum StudyError {
13    /// Config could not load or validate project declarations.
14    #[error("failed to load project declarations")]
15    Config(#[from] ConfigError),
16
17    /// State rejected the centrally parsed state-schema document.
18    #[error("failed to validate the project state schema")]
19    State(#[from] StateError),
20
21    /// Compiled model registrations are invalid or ambiguous.
22    #[error("invalid compiled model registration: {reason}")]
23    InvalidModelRegistration {
24        /// Stable explanation of the invalid or duplicate registration.
25        reason: String,
26    },
27
28    /// A manifest task references no compiled model.
29    #[error("phase `{phase}` references unregistered model `{model}`")]
30    UnknownModel {
31        /// Phase containing the unresolved reference.
32        phase: String,
33        /// Stable model key requested by the manifest.
34        model: String,
35    },
36
37    /// Typed constants or observation-plan binding failed during model preflight.
38    #[error(
39        "model `{model}` failed preflight for resolved parameters {ordinal} in phase `{phase}`"
40    )]
41    ModelPreflight {
42        /// Phase containing the rejected invocation.
43        phase: String,
44        /// Stable compiled model key.
45        model: String,
46        /// Deterministic parameter expansion ordinal.
47        ordinal: u64,
48        /// Original config, observation, or model-declaration error.
49        #[source]
50        source: Box<dyn std::error::Error + Send + Sync + 'static>,
51    },
52
53    /// The total expanded task count cannot be represented by stable ordinals.
54    #[error("the study contains more expanded task invocations than can be identified")]
55    TaskIdentityOverflow,
56}
57
58impl From<ModelCatalogError> for StudyError {
59    fn from(source: ModelCatalogError) -> Self {
60        Self::InvalidModelRegistration {
61            reason: source.to_string(),
62        }
63    }
64}
65
66impl StudyError {
67    pub(crate) fn model_preflight(
68        phase: &str,
69        model: &str,
70        ordinal: u64,
71        source: Box<dyn std::error::Error + Send + Sync + 'static>,
72    ) -> Self {
73        Self::ModelPreflight {
74            phase: phase.to_owned(),
75            model: model.to_owned(),
76            ordinal,
77            source,
78        }
79    }
80}