terraform_version/
error.rs

1use crate::Operator;
2
3pub type Result<T, E = Error> = std::result::Result<T, E>;
4
5#[derive(Debug, thiserror::Error, miette::Diagnostic, PartialEq, Eq)]
6pub enum Error {
7    /// No version for parsing.
8    #[error("No version filled in")]
9    NoVersion,
10
11    /// No version requirement for parsing.
12    #[error("No version requirement filled in")]
13    NoVersionRequirement,
14
15    /// Trying to parse version requirement with suffix whereas `operator` is not `Exact` neither `Different`.
16    #[error("Operator `{0}` forbidden. Non-empty suffix is only allowed if operator is Exact of Different")]
17    NotAllowedOperatorWithSuffix(Operator),
18
19    /// Trying to parse version requirement with invalid `operator`.
20    #[error("Invalid operator in comparator : `{0}`")]
21    InvalidOperator(String),
22
23    /// Trying to parse version requirement with multiple comparators whereas one has the operator `Exact`.
24    #[error("Impossible to parse version requirement `{0}`. Operator `Exact` is forbidden in multi comparator. Consider removing either the exact operator comparator, or all others.")]
25    NotAllowedOperatorWithMultipleComparators(String),
26
27    /// Trying to parse numeric identifier from non number.
28    #[error("Impossible to parse numeric identifier `{text}` : `{ni}` is not a number")]
29    ImpossibleNumericIdentifierParsing {
30        #[source]
31        err: std::num::ParseIntError,
32        text: String,
33        ni: String,
34    },
35}