use std::path::{Path, PathBuf};
use thiserror::Error;
use crate::config::ConfigError;
use crate::state::StateError;
use crate::task::ExecutionUnitCatalogError;
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum StudyError {
#[error("failed to load project declarations")]
Config(#[from] ConfigError),
#[error("failed to validate state schema `{state}` from `{path}`")]
State {
state: String,
path: PathBuf,
#[source]
source: StateError,
},
#[error("failed to validate standard state-schema provider `{provider}`")]
ProvidedState {
provider: String,
#[source]
source: StateError,
},
#[error("invalid standard state-schema provider `{provider}`: {reason}")]
InvalidStateSchemaProvider {
provider: String,
reason: String,
},
#[error("invalid compiled execution-unit registration: {reason}")]
InvalidExecutionUnitRegistration {
reason: String,
},
#[error("phase `{phase}` references unregistered execution unit `{execution_unit}`")]
UnknownExecutionUnit {
phase: String,
execution_unit: String,
},
#[error(
"execution unit `{execution_unit}` in phase `{phase}` does not declare thread-count-invariant execution required by automatic compute allocation"
)]
AutoComputeRequiresInvariantUnit {
phase: String,
execution_unit: String,
},
#[error(
"execution unit `{execution_unit}` in phase `{phase}` requires an explicit project state because it has no standard state-schema provider"
)]
MissingStateSchema {
phase: String,
execution_unit: String,
},
#[error(
"execution unit `{execution_unit}` failed preflight for resolved parameters {ordinal} in phase `{phase}`"
)]
ExecutionUnitPreflight {
phase: String,
execution_unit: String,
ordinal: u64,
#[source]
source: Box<dyn std::error::Error + Send + Sync + 'static>,
},
#[error("the study contains more expanded task invocations than can be identified")]
TaskIdentityOverflow,
}
impl From<ExecutionUnitCatalogError> for StudyError {
fn from(source: ExecutionUnitCatalogError) -> Self {
Self::InvalidExecutionUnitRegistration {
reason: source.to_string(),
}
}
}
impl StudyError {
pub(crate) fn state_schema(state: &str, path: &Path, source: StateError) -> Self {
Self::State {
state: state.to_owned(),
path: path.to_path_buf(),
source,
}
}
pub(crate) fn execution_unit_preflight(
phase: &str,
execution_unit: &str,
ordinal: u64,
source: Box<dyn std::error::Error + Send + Sync + 'static>,
) -> Self {
Self::ExecutionUnitPreflight {
phase: phase.to_owned(),
execution_unit: execution_unit.to_owned(),
ordinal,
source,
}
}
}