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