-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: change the code to use
FluereError
- Loading branch information
1 parent
fd7a81b
commit 447343e
Showing
8 changed files
with
104 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,56 @@ | ||
use snafu::prelude::*; | ||
use std::{io, path::PathBuf}; | ||
|
||
#[derive(Debug, Snafu)] | ||
#[snafu(visibility(pub))] | ||
#[derive(Debug)] | ||
pub enum NetError { | ||
#[snafu(display("unexpected empty packet"))] | ||
EmptyPacket, | ||
#[snafu(display("unknown Protocol `{protocol}`"))] | ||
UnknownProtocol { protocol: String }, | ||
#[snafu(display("unknown IP version `{version}`"))] | ||
UnknownIPVersion { version: String }, | ||
} | ||
#[derive(Debug, Snafu)] | ||
#[snafu(visibility(pub))] | ||
pub enum ParseError { | ||
#[snafu(display("unexpected dscp `{dscp}`"))] | ||
UnknownDSCP { dscp: u8 }, | ||
DeviceNotFound { name: String }, | ||
CaptureError { msg: String }, | ||
PacketParseError { msg: String }, | ||
PluginError { msg: String }, | ||
FileError { path: PathBuf }, | ||
InterfaceError { msg: String }, | ||
// Add new variants for parameter errors | ||
ParameterError { name: String, msg: String }, | ||
IoError(io::Error), | ||
ParseError { value: String, type_name: String }, | ||
} | ||
|
||
impl std::fmt::Display for NetError { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
Self::EmptyPacket => write!(f, "Unexpected empty packet"), | ||
Self::UnknownProtocol { protocol } => write!(f, "Unknown protocol `{}`", protocol), | ||
Self::UnknownIPVersion { version } => write!(f, "Unknown IP version `{}`", version), | ||
Self::UnknownDSCP { dscp } => write!(f, "Unexpected DSCP value `{}`", dscp), | ||
Self::DeviceNotFound { name } => write!(f, "Network device not found: {}", name), | ||
Self::CaptureError { msg } => write!(f, "Capture error: {}", msg), | ||
Self::PacketParseError { msg } => write!(f, "Packet parse error: {}", msg), | ||
Self::PluginError { msg } => write!(f, "Plugin error: {}", msg), | ||
Self::FileError { path } => write!(f, "File operation error: {}", path.display()), | ||
Self::InterfaceError { msg } => write!(f, "Interface error: {}", msg), | ||
Self::ParameterError { name, msg } => write!(f, "Parameter '{}' error: {}", name, msg), | ||
Self::IoError(e) => write!(f, "IO error: {}", e), | ||
Self::ParseError { value, type_name } => { | ||
write!(f, "Failed to parse '{}' as {}", value, type_name) | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl From<io::Error> for NetError { | ||
fn from(error: io::Error) -> Self { | ||
NetError::IoError(error) | ||
} | ||
} | ||
|
||
impl From<std::num::ParseIntError> for NetError { | ||
fn from(error: std::num::ParseIntError) -> Self { | ||
NetError::ParseError { | ||
value: error.to_string(), | ||
type_name: "integer".to_string(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters