Skip to main content

scientific_workflow/config/
error.rs

1//! Configuration-owned project loading and parameter resolution failures.
2
3use std::io;
4use std::path::PathBuf;
5
6use thiserror::Error;
7
8/// A failure while compiling project documents into a specification.
9#[derive(Debug, Error)]
10#[non_exhaustive]
11pub enum ConfigError {
12    /// A required project document could not be read.
13    #[error("failed to read project document `{path}`")]
14    Read {
15        /// Document or directory path involved in the failed operation.
16        path: PathBuf,
17        /// Underlying filesystem failure.
18        #[source]
19        source: io::Error,
20    },
21
22    /// A project document was not valid JSON.
23    #[error("failed to parse project document `{path}`")]
24    Parse {
25        /// Source document containing invalid JSON.
26        path: PathBuf,
27        /// Underlying JSON syntax failure.
28        #[source]
29        source: serde_json::Error,
30    },
31
32    /// A JSON object repeated a key.
33    #[error("project document `{path}` repeats key `{key}`")]
34    DuplicateKey {
35        /// Source document containing the duplicate.
36        path: PathBuf,
37        /// Repeated object key.
38        key: String,
39    },
40
41    /// Valid JSON did not satisfy its document grammar.
42    #[error("invalid project document `{path}` at `{pointer}`: {reason}")]
43    InvalidDocument {
44        /// Rejected source document.
45        path: PathBuf,
46        /// Nearest meaningful JSON Pointer, or `/` for the root.
47        pointer: String,
48        /// Contextual grammar violation.
49        reason: String,
50    },
51
52    /// A discovered document escaped the project configuration directory.
53    #[error("document path `{path}` is outside configuration root `{config_root}`")]
54    PathOutsideConfig {
55        /// Rejected authored or resolved path.
56        path: PathBuf,
57        /// Canonical project configuration root.
58        config_root: PathBuf,
59    },
60
61    /// A program or Python task did not resolve to a valid executable, script,
62    /// or environment.
63    #[error("invalid program task path `{path}`: {reason}")]
64    InvalidProgram {
65        /// Authored program path or command name.
66        path: PathBuf,
67        /// Stable resolution or validation failure.
68        reason: String,
69    },
70
71    /// A phase dependency does not name a declared phase.
72    #[error("phase `{phase}` depends on unknown phase `{dependency}`")]
73    UnknownDependency {
74        /// Referring phase.
75        phase: String,
76        /// Missing dependency.
77        dependency: String,
78    },
79
80    /// A model-parameter expansion cannot be represented safely.
81    #[error("model parameter expansion in `{path}` exceeds supported combination counts")]
82    ExpansionOverflow {
83        /// Parameters document whose selection product overflowed.
84        path: PathBuf,
85    },
86
87    /// One resolved parameter combination could not decode as model constants.
88    #[error(
89        "failed to decode resolved parameter combination {ordinal} for model `{model}` from `{path}`"
90    )]
91    DecodeModelConstants {
92        /// Compiled model key from the study manifest.
93        model: String,
94        /// Central parameters document path.
95        path: PathBuf,
96        /// Zero-based deterministic combination ordinal.
97        ordinal: u64,
98        /// Underlying Serde conversion failure.
99        #[source]
100        source: serde_json::Error,
101    },
102}
103
104impl ConfigError {
105    pub(crate) fn invalid(
106        path: &std::path::Path,
107        pointer: impl Into<String>,
108        reason: impl Into<String>,
109    ) -> Self {
110        Self::InvalidDocument {
111            path: path.to_path_buf(),
112            pointer: pointer.into(),
113            reason: reason.into(),
114        }
115    }
116}