use thiserror::Error;
use super::{SUPPORTED_VERSION, schema};
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum PolicyError {
#[error("policy parse error (policy schema version {SUPPORTED_VERSION}): {0}")]
Parse(crate::yaml::Error),
#[error("{}", schema::unsupported(*found, *supported))]
Version {
found: u32,
supported: u32,
},
#[error(
"the policy has no `version:`; add `version: {supported}` as its first key, the policy \
schema version this build reads (`openmoat policy migrate` adds it)"
)]
MissingVersion {
supported: u32,
},
#[error("duplicate rule id `{0}`")]
DuplicateId(String),
#[error("rule `{0}` has no patterns")]
EmptyRule(String),
#[error("empty pattern")]
EmptyPattern,
#[error("bad glob `{pattern}`: {error}")]
BadGlob {
pattern: String,
error: globset::Error,
},
#[error("bad shell pattern `{pattern}` (unbalanced quotes?)")]
BadShellPattern {
pattern: String,
},
#[error(
"the policy has both `{old}:` and `{new}:`; `{old}` is the old name of `{new}`: \
move the `{old}:` rules into `{new}:` (`openmoat policy upgrade` renames a policy \
that has only `{old}:`)"
)]
OldAndNewName {
old: &'static str,
new: &'static str,
},
#[error("rule `{rule}`: {problem}")]
Rule {
rule: String,
problem: String,
},
}