diff options
-rw-r--r-- | src/lib.rs | 11 |
1 files changed, 10 insertions, 1 deletions
@@ -15,6 +15,7 @@ use tokio::runtime::Runtime; pub enum Error { RtNetlink(rtnetlink::Error), IoError(std::io::Error), + LinkNotFound(Option<String>), } impl std::error::Error for Error {} @@ -24,6 +25,10 @@ impl fmt::Display for Error { match self { Self::RtNetlink(e) => write!(fmt, "rtnetlink error: {}", e), Self::IoError(e) => write!(fmt, "rtnetlink connection failed: {}", e), + Self::LinkNotFound(filter) => match filter { + Some(link) => write!(fmt, "link not found: {}", link), + None => write!(fmt, "no links found"), + }, } } } @@ -166,5 +171,9 @@ async fn internal_addresses(filter: Option<String>) -> Result<Vec<IpNet>> { num_links.add_assign(1); } - Ok(link_addrs) + if num_links > 0 { + Ok(link_addrs) + } else { + Err(Error::LinkNotFound(filter)) + } } |