huginn_net/error.rs
1use pnet::packet::ethernet::EtherType;
2use thiserror::Error;
3
4/// Error handling during network packet analysis and Database parsing.
5#[derive(Error, Debug)]
6pub enum HuginnNetError {
7 /// An error occurred while parsing data.
8 ///
9 /// This variant is used when a parsing operation fails.
10 /// The associated string provides additional context about the error.
11 #[error("Parse error: {0}")]
12 Parse(String),
13
14 /// An unsupported protocol was encountered.
15 ///
16 /// This variant is used when a protocol is not supported by the application.
17 /// The associated string specifies the unsupported protocol.
18 #[error("Unsupported protocol: {0}")]
19 UnsupportedProtocol(String),
20
21 /// Invalid TCP flags were detected.
22 ///
23 /// This variant is used when TCP flags are invalid or unexpected.
24 /// The associated value provides the invalid flags.
25 #[error("Invalid TCP flags: {0}")]
26 InvalidTcpFlags(u8),
27
28 /// An invalid package was encountered.
29 ///
30 /// This variant is used when a package is deemed invalid.
31 /// The associated string provides details about the invalid package.
32 #[error("Invalid package: {0}")]
33 UnexpectedPackage(String),
34
35 /// An unsupported Ethernet type was encountered.
36 ///
37 /// This variant is used when an Ethernet type is not supported.
38 /// The associated value specifies the unsupported Ethernet type.
39 #[error("Unsupported ethernet type: {0}")]
40 UnsupportedEthernetType(EtherType),
41
42 /// Unacceptable configuration.
43 ///
44 /// This variant is used when the configuration is unacceptable.
45 /// The associated value specifies the unacceptable configuration.
46 #[error("Unacceptable configuration: {0}")]
47 MissConfiguration(String),
48
49 /// An unknown error occurred.
50 ///
51 /// This variant is used as a catch-all for errors that do not fit other categories.
52 #[error("Unknown error")]
53 Unknown,
54}
55
56impl From<huginn_net_db::error::DatabaseError> for HuginnNetError {
57 fn from(err: huginn_net_db::error::DatabaseError) -> Self {
58 HuginnNetError::MissConfiguration(format!("Database error: {err}"))
59 }
60}