Skip to main content

goliath_normalize/
error.rs

1//! Error types.
2
3use goliath_rule::PathError;
4use goliath_sigma::YamlError;
5use thiserror::Error;
6
7/// A source definition that cannot be loaded.
8#[derive(Debug, Clone, PartialEq, Eq, Error)]
9#[non_exhaustive]
10pub enum DefinitionError {
11    /// The file is not acceptable YAML, or does not have the shape of a
12    /// source definition.
13    #[error(transparent)]
14    Yaml(#[from] YamlError),
15
16    /// A path into the OCSF event cannot be parsed.
17    #[error("kind `{kind}`: target `{target}`: {source}")]
18    Target {
19        /// The kind the field belongs to, or `common`.
20        kind: String,
21        /// The target as written.
22        target: String,
23        /// Why it cannot be parsed.
24        source: PathError,
25    },
26
27    /// A path into the decoded record cannot be parsed.
28    #[error("kind `{kind}`: source path `{path}` has an empty segment")]
29    SourcePath {
30        /// The kind the path belongs to, or `common`.
31        kind: String,
32        /// The path as written.
33        path: String,
34    },
35
36    /// Two fields write the same attribute, or one writes inside another,
37    /// so one of them would be lost.
38    #[error("kind `{kind}`: targets `{first}` and `{second}` overlap")]
39    Overlap {
40        /// The kind the fields belong to, with the common fields included.
41        kind: String,
42        /// One target.
43        first: String,
44        /// The other.
45        second: String,
46    },
47
48    /// A field writes an attribute the definition may not set directly.
49    #[error("kind `{kind}`: `{target}` is set by {reason}, not by a field")]
50    Reserved {
51        /// The kind the field belongs to, or `common`.
52        kind: String,
53        /// The target as written.
54        target: String,
55        /// What sets it instead.
56        reason: &'static str,
57    },
58
59    /// A kind has no condition, so it would accept every record and hide the
60    /// kinds after it.
61    #[error("kind `{kind}` has no `when` condition")]
62    Unconditional {
63        /// The kind.
64        kind: String,
65    },
66
67    /// The definition has no kinds, so every record would be rejected.
68    #[error("the definition has no kinds")]
69    NoKinds,
70}