openvet_policy/error.rs
1/// Error returned by the policy parser and validator.
2#[derive(Debug, thiserror::Error)]
3pub enum PolicyError {
4 /// I/O error reading the policy file.
5 #[error("io error: {0}")]
6 Io(#[from] std::io::Error),
7 /// TOML parse error.
8 #[error("toml parse error: {0}")]
9 Toml(#[from] toml::de::Error),
10 /// A requirement expression failed to parse (bad token,
11 /// trailing tokens, unbalanced parens, empty input, etc.).
12 #[error("expression: {0}")]
13 ExprParse(String),
14 /// A requirement's condition expression failed to parse. Carries
15 /// the requirement name as context; the wrapped error is the
16 /// underlying [`ExprParse`](Self::ExprParse).
17 #[error("requirement {name:?}: {source}")]
18 RequirementExpression {
19 /// The requirement whose expression failed to parse.
20 name: String,
21 /// The underlying parse error.
22 #[source]
23 source: Box<PolicyError>,
24 },
25 /// An `[[override]]` block references a requirement name that
26 /// isn't defined in `[requirement]`.
27 #[error("override references unknown requirement {name:?}")]
28 UnknownRequirement {
29 /// The name referenced by the override.
30 name: String,
31 },
32 /// An `[alias]` entry isn't in `log:claim-name` form (missing
33 /// the `:` separator).
34 #[error("alias {canonical:?}: entry {entry:?} must be `log:claim-name`")]
35 InvalidAliasEntry {
36 /// The canonical claim name the alias was being defined for.
37 canonical: String,
38 /// The offending right-hand-side entry.
39 entry: String,
40 },
41}
42
43/// Convenience type alias for `Result<T, PolicyError>`.
44pub type Result<T, E = PolicyError> = std::result::Result<T, E>;