oxideshield_core/
error.rs1use thiserror::Error;
4
5pub type Result<T> = std::result::Result<T, Error>;
7
8#[derive(Error, Debug)]
10pub enum Error {
11 #[error("Failed to compile pattern: {0}")]
13 PatternCompilation(String),
14
15 #[error("Invalid pattern syntax: {0}")]
17 InvalidPattern(String),
18
19 #[error("Configuration error: {0}")]
21 Config(String),
22
23 #[error("IO error: {0}")]
25 Io(#[from] std::io::Error),
26
27 #[error("YAML parsing error: {0}")]
29 Yaml(#[from] serde_saphyr::Error),
30
31 #[error("JSON parsing error: {0}")]
33 Json(#[from] serde_json::Error),
34
35 #[error("Regex error: {0}")]
37 Regex(#[from] regex::Error),
38
39 #[error("Aho-Corasick build error: {0}")]
41 AhoCorasick(#[from] aho_corasick::BuildError),
42
43 #[error("Tokenizer error: {0}")]
45 Tokenizer(String),
46
47 #[error("Guard validation failed: {0}")]
49 GuardValidation(String),
50
51 #[error("Probe execution failed: {0}")]
53 ProbeExecution(String),
54
55 #[error("Network error: {0}")]
57 Network(String),
58
59 #[error("{context}: {source}")]
61 WithContext {
62 context: String,
63 #[source]
64 source: Box<Error>,
65 },
66}
67
68impl Error {
69 pub fn with_context(self, context: impl Into<String>) -> Self {
71 Error::WithContext {
72 context: context.into(),
73 source: Box::new(self),
74 }
75 }
76}