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