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 framing and the decoding cannot be used together.
69 #[error("framing `{framing}` cannot be used with decoding `{decoding}`")]
70 Decoding {
71 /// The framing as written.
72 framing: &'static str,
73 /// The decoding as written.
74 decoding: &'static str,
75 },
76
77 /// The definition decodes rows and does not name their columns, or
78 /// names columns and decodes something else.
79 #[error("`columns` is needed by decoding `csv`, and by no other")]
80 Columns,
81
82 /// The definition has no kinds, so every record would be rejected.
83 #[error("the definition has no kinds")]
84 NoKinds,
85
86 /// A kind names a class the OCSF schema does not define.
87 #[error("kind `{kind}`: OCSF {version} has no class {class_uid}")]
88 UnknownClass {
89 /// The kind.
90 kind: String,
91 /// The `class_uid` as written.
92 class_uid: u32,
93 /// The schema version checked against.
94 version: &'static str,
95 },
96
97 /// A kind names an activity its class does not define.
98 #[error("kind `{kind}`: class `{class}` has no activity {activity_id}")]
99 UnknownActivity {
100 /// The kind.
101 kind: String,
102 /// The class name.
103 class: &'static str,
104 /// The `activity_id` as written.
105 activity_id: u32,
106 },
107
108 /// A target is not an attribute of the kind's class.
109 #[error("kind `{kind}`: {source}")]
110 Attribute {
111 /// The kind; a common field is reported for the first kind it fails
112 /// in.
113 kind: String,
114 /// Where the path left the schema.
115 source: SchemaPathError,
116 },
117
118 /// A field writes a value the attribute cannot hold.
119 #[error("kind `{kind}`: `{target}` holds {holds}, but the field writes {writes}")]
120 Type {
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 /// What the attribute holds, such as `` `integer_t` ``.
127 holds: String,
128 /// What the field writes, such as `text`.
129 writes: &'static str,
130 },
131
132 /// A constant is not one of the values an enumerated attribute defines.
133 #[error("kind `{kind}`: {value} is not a defined value of `{target}`")]
134 UnknownValue {
135 /// The kind; a common field is reported for the first kind it fails
136 /// in.
137 kind: String,
138 /// The target as written.
139 target: String,
140 /// The constant.
141 value: i64,
142 },
143
144 /// A translation table is empty, or its values are not all of one type.
145 #[error("kind `{kind}`: the translation for `{target}` {reason}")]
146 Translation {
147 /// The kind the field belongs to, or `common`.
148 kind: String,
149 /// The target as written.
150 target: String,
151 /// What is wrong with the table.
152 reason: &'static str,
153 },
154
155 /// A target lies inside an array without naming an element of it, so
156 /// there is no one place to write it.
157 #[error(
158 "kind `{kind}`: `{target}` is inside an array; name an element by its index after the array, such as `0`"
159 )]
160 WithinArray {
161 /// The kind; a common field is reported for the first kind it fails
162 /// in.
163 kind: String,
164 /// The target as written.
165 target: String,
166 },
167
168 /// A target names an element of an attribute that is not an array.
169 #[error("kind `{kind}`: `{target}` names an element of `{attribute}`, which is not an array")]
170 NotAnArray {
171 /// The kind; a common field is reported for the first kind it fails
172 /// in.
173 kind: String,
174 /// The target as written.
175 target: String,
176 /// The attribute before the index.
177 attribute: String,
178 },
179}