Skip to main content

cvss_rs/
error.rs

1use thiserror::Error;
2
3/// Errors that can occur when parsing CVSS vector strings.
4#[derive(Clone, Debug, PartialEq, Error)]
5pub enum ParseError {
6    /// Vector string is malformed (e.g., missing '/' separators)
7    #[error("malformed vector string: no '/' separator found")]
8    MalformedVectorString,
9    /// Vector string doesn't start with "CVSS:"
10    #[error("invalid vector prefix: expected prefix to start with 'CVSS:', found '{found}'")]
11    InvalidPrefixLabel { found: String },
12    /// CVSS version has unexpected format
13    #[error("malformed CVSS version format: '{version}' (expected 'X.Y')")]
14    MalformedPrefixVersion { version: String },
15    /// Unsupported or invalid CVSS version
16    #[error("invalid or unsupported CVSS version: '{version}'")]
17    InvalidPrefixVersion { version: String },
18    /// Component is malformed (not in key:value format)
19    #[error("invalid component format: '{component}' (expected 'KEY:VALUE')")]
20    InvalidComponent { component: String },
21    /// Metric abbreviation not recognized
22    #[error("unknown metric abbreviation: '{metric}'")]
23    UnknownMetric { metric: String },
24    /// Metric value parsing failed
25    #[error("invalid value '{value}' for metric '{metric}'")]
26    InvalidMetricValue { metric: String, value: String },
27    /// Required base metric is missing
28    #[error("missing required metric: '{metric}'")]
29    MissingRequiredMetric { metric: String },
30    /// Same metric appears multiple times
31    #[error("duplicate metric: '{metric}'")]
32    DuplicateMetric { metric: String },
33}