goliath_normalize/error.rs
1//! Error types.
2
3use goliath_ocsf::schema::PathError as SchemaPathError;
4use goliath_rule::PathError;
5use goliath_sigma::YamlError;
6use thiserror::Error;
7
8/// A source definition that cannot be loaded.
9#[derive(Debug, Clone, PartialEq, Eq, Error)]
10#[non_exhaustive]
11pub enum DefinitionError {
12 /// The file is not acceptable YAML, or does not have the shape of a
13 /// source definition.
14 #[error(transparent)]
15 Yaml(#[from] YamlError),
16
17 /// A path into the OCSF event cannot be parsed.
18 #[error("kind `{kind}`: target `{target}`: {source}")]
19 Target {
20 /// The kind the field belongs to, or `common`.
21 kind: String,
22 /// The target as written.
23 target: String,
24 /// Why it cannot be parsed.
25 source: PathError,
26 },
27
28 /// A path into the decoded record cannot be parsed.
29 #[error("kind `{kind}`: source path `{path}` has an empty segment")]
30 SourcePath {
31 /// The kind the path belongs to, or `common`.
32 kind: String,
33 /// The path as written.
34 path: String,
35 },
36
37 /// Two fields write the same attribute, or one writes inside another,
38 /// so one of them would be lost.
39 #[error("kind `{kind}`: targets `{first}` and `{second}` overlap")]
40 Overlap {
41 /// The kind the fields belong to, with the common fields included.
42 kind: String,
43 /// One target.
44 first: String,
45 /// The other.
46 second: String,
47 },
48
49 /// A field writes an attribute the definition may not set directly.
50 #[error("kind `{kind}`: `{target}` is set by {reason}, not by a field")]
51 Reserved {
52 /// The kind the field belongs to, or `common`.
53 kind: String,
54 /// The target as written.
55 target: String,
56 /// What sets it instead.
57 reason: &'static str,
58 },
59
60 /// A kind has no condition, so it would accept every record and hide the
61 /// kinds after it.
62 #[error("kind `{kind}` has no `when` condition")]
63 Unconditional {
64 /// The kind.
65 kind: String,
66 },
67
68 /// The definition has no kinds, so every record would be rejected.
69 #[error("the definition has no kinds")]
70 NoKinds,
71
72 /// A kind names a class the OCSF schema does not define.
73 #[error("kind `{kind}`: OCSF {version} has no class {class_uid}")]
74 UnknownClass {
75 /// The kind.
76 kind: String,
77 /// The `class_uid` as written.
78 class_uid: u32,
79 /// The schema version checked against.
80 version: &'static str,
81 },
82
83 /// A kind names an activity its class does not define.
84 #[error("kind `{kind}`: class `{class}` has no activity {activity_id}")]
85 UnknownActivity {
86 /// The kind.
87 kind: String,
88 /// The class name.
89 class: &'static str,
90 /// The `activity_id` as written.
91 activity_id: u32,
92 },
93
94 /// A target is not an attribute of the kind's class.
95 #[error("kind `{kind}`: {source}")]
96 Attribute {
97 /// The kind; a common field is reported for the first kind it fails
98 /// in.
99 kind: String,
100 /// Where the path left the schema.
101 source: SchemaPathError,
102 },
103
104 /// A field writes a value the attribute cannot hold.
105 #[error("kind `{kind}`: `{target}` holds {holds}, but the field writes {writes}")]
106 Type {
107 /// The kind; a common field is reported for the first kind it fails
108 /// in.
109 kind: String,
110 /// The target as written.
111 target: String,
112 /// What the attribute holds, such as `` `integer_t` ``.
113 holds: String,
114 /// What the field writes, such as `text`.
115 writes: &'static str,
116 },
117
118 /// A constant is not one of the values an enumerated attribute defines.
119 #[error("kind `{kind}`: {value} is not a defined value of `{target}`")]
120 UnknownValue {
121 /// The kind; a common field is reported for the first kind it fails
122 /// in.
123 kind: String,
124 /// The target as written.
125 target: String,
126 /// The constant.
127 value: i64,
128 },
129
130 /// A translation table is empty, or its values are not all of one type.
131 #[error("kind `{kind}`: the translation for `{target}` {reason}")]
132 Translation {
133 /// The kind the field belongs to, or `common`.
134 kind: String,
135 /// The target as written.
136 target: String,
137 /// What is wrong with the table.
138 reason: &'static str,
139 },
140
141 /// A target lies inside an array, so there is no one place to write it.
142 #[error("kind `{kind}`: `{target}` is inside an array, which a field cannot write into")]
143 WithinArray {
144 /// The kind; a common field is reported for the first kind it fails
145 /// in.
146 kind: String,
147 /// The target as written.
148 target: String,
149 },
150}