#[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub enum FindingBuildError {
EmptyScanner,
EmptyTarget,
EmptyTitle,
InvalidConfidence,
InvalidCvssScore,
InvalidCveFormat(String),
InvalidCweFormat(String),
FieldTooLong {
field: &'static str,
max: usize,
},
InvalidField {
field: &'static str,
reason: &'static str,
},
TooManyItems {
field: &'static str,
max: usize,
},
UnsupportedVersion {
actual: u32,
expected: u32,
},
}
impl std::fmt::Display for FindingBuildError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::EmptyScanner => write!(
f,
"scanner cannot be empty. Fix: pass the tool or scanner name that produced the finding."
),
Self::EmptyTarget => write!(
f,
"target cannot be empty. Fix: pass the URL, host, file path, or asset identifier that was scanned."
),
Self::EmptyTitle => write!(
f,
"title cannot be empty. Fix: provide a short finding summary such as `Exposed admin panel`."
),
Self::InvalidConfidence => write!(
f,
"confidence cannot be NaN. Fix: use a finite confidence score between 0.0 and 1.0."
),
Self::InvalidCvssScore => write!(
f,
"cvss_score cannot be NaN. Fix: use a finite CVSS score between 0.0 and 10.0."
),
Self::InvalidCveFormat(cve) => {
write!(f, "invalid CVE format: `{cve}`. Fix: use values like `CVE-2024-12345`.")
}
Self::InvalidCweFormat(cwe) => {
write!(f, "invalid CWE format: `{cwe}`. Fix: use values like `CWE-89`.")
}
Self::FieldTooLong { field, max } => write!(
f,
"field `{field}` exceeds maximum length of {max} bytes. Fix: shorten or truncate the `{field}` to <= {max} bytes before building the Finding or increase the allowed maximum."
),
Self::InvalidField { field, reason } => {
write!(f, "field `{field}` is invalid: {reason}. Fix: sanitize the input before building the Finding.")
}
Self::TooManyItems { field, max } => write!(
f,
"field `{field}` contains too many items (max {max}). Fix: reduce the number of items in `{field}`."
),
Self::UnsupportedVersion { actual, expected } => write!(
f,
"unsupported finding format version {actual}, expected {expected}. Fix: update the producing tool to emit version {expected} findings."
),
}
}
}
impl std::error::Error for FindingBuildError {}