use goliath_ocsf::schema::PathError as SchemaPathError;
use goliath_sigma::YamlError;
use thiserror::Error;
use crate::mapping::LogSourceSelector;
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq, Eq, Error)]
pub enum PathError {
#[error("field path is empty")]
Empty,
#[error("field path `{path}` has an empty segment at position {position}")]
EmptySegment {
path: String,
position: usize,
},
}
#[derive(Debug, Clone, PartialEq, Eq, Error)]
#[error("`{0}` is not an IP address or network")]
pub struct NetworkError(pub String);
#[derive(Debug, Clone, PartialEq, Eq, Error)]
#[non_exhaustive]
pub enum MappingError {
#[error(transparent)]
Yaml(#[from] YamlError),
#[error("mapping {index} selects every log source; name at least one key")]
EmptySelector {
index: usize,
},
#[error("mapping {index} maps field `{field}` to no path")]
NoPaths {
index: usize,
field: String,
},
#[error("mappings {earlier} and {index} have the same log source selector")]
DuplicateSelector {
earlier: usize,
index: usize,
},
#[error("mapping {index}: OCSF {version} has no class {class_uid}")]
UnknownClass {
index: usize,
class_uid: i64,
version: &'static str,
},
#[error("mapping {index}: {source}")]
Attribute {
index: usize,
source: SchemaPathError,
},
#[error("mapping {index}: `{path}` holds {holds}, which cannot equal {value}")]
Type {
index: usize,
path: String,
holds: String,
value: String,
},
#[error("mapping {index}: {value} is not a defined value of `{path}`")]
UnknownValue {
index: usize,
path: String,
value: i64,
},
#[error("no mapping for log source ({logsource})")]
NoMapping {
logsource: LogSourceSelector,
},
#[error("more than one mapping applies equally to log source ({logsource})")]
Ambiguous {
logsource: LogSourceSelector,
},
}
#[derive(Debug, Clone, PartialEq, Eq, Error)]
#[non_exhaustive]
pub enum ResolveError {
#[error(transparent)]
Mapping(#[from] MappingError),
#[error("field `{field}` has no mapping for log source ({logsource})")]
UnmappedField {
field: String,
logsource: LogSourceSelector,
},
#[error("field `{field}` uses `{modifier}`, which is not supported")]
UnsupportedModifier {
field: String,
modifier: &'static str,
},
#[error("field `{field}`: {reason}")]
InvalidValue {
field: String,
reason: &'static str,
},
#[error("field `{field}` expands into {count} variants")]
TooManyVariants {
field: String,
count: usize,
},
#[error("a keyword must be text, found {found}")]
UnsupportedKeyword {
found: &'static str,
},
}