Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ authors = ["Leo Borai <estebanborai@gmail.com>"]
edition = "2021"
readme = "README.md"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
thiserror = "2"

[target.'cfg(unix)'.dependencies]
libc = "0.2"
Expand Down
28 changes: 24 additions & 4 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,34 @@
#[derive(thiserror::Error, Debug, PartialEq)]
use std::fmt;

#[derive(Debug, PartialEq)]
pub enum Error {
/// Returned when `local_ip` is unable to find the system's local IP address
/// in the collection of network interfaces
#[error("The Local IP Address wasn't available in the network interfaces list/table")]
LocalIpAddressNotFound,
/// Returned when an error occurs in the strategy level.
/// The error message may include any internal strategy error if available
#[error("An error occurred executing the underlying strategy error.\n{0}")]
StrategyError(String),
/// Returned when the current platform is not yet supported
#[error("The current platform: `{0}`, is not supported")]
PlatformNotSupported(String),
}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::LocalIpAddressNotFound => write!(
f,
"The Local IP Address wasn't available in the network interfaces list/table"
),
Error::StrategyError(msg) => write!(
f,
"An error occurred executing the underlying strategy error.\n{}",
msg
),
Error::PlatformNotSupported(platform) => {
write!(f, "The current platform: `{}`, is not supported", platform)
}
}
}
}

impl std::error::Error for Error {}
Loading