summaryrefslogtreecommitdiffstats
path: root/src/os/shared.rs
diff options
context:
space:
mode:
authorcyqsimon <28627918+cyqsimon@users.noreply.github.com>2023-08-25 19:02:37 +0800
committercyqsimon <28627918+cyqsimon@users.noreply.github.com>2023-08-25 19:02:37 +0800
commitffbf0cd8aa73ed3db3e9dc01f154eacb5fe1130c (patch)
tree7e20ef11e08466f09044d6423319779d1d70919b /src/os/shared.rs
parentc780c06807fbed4388eb5636c30a4cc11eeb814c (diff)
Migrate from `failure` to `anyhow`+`thiserror`
Diffstat (limited to 'src/os/shared.rs')
-rw-r--r--src/os/shared.rs24
1 files changed, 12 insertions, 12 deletions
diff --git a/src/os/shared.rs b/src/os/shared.rs
index f28e49e..f8d997d 100644
--- a/src/os/shared.rs
+++ b/src/os/shared.rs
@@ -9,7 +9,7 @@ use ::tokio::runtime::Runtime;
use ::std::net::Ipv4Addr;
use ::std::time;
-use crate::os::errors::GetInterfaceErrorKind;
+use crate::os::errors::GetInterfaceError;
#[cfg(target_os = "linux")]
use crate::os::linux::get_open_sockets;
@@ -34,7 +34,7 @@ impl Iterator for TerminalEvents {
pub(crate) fn get_datalink_channel(
interface: &NetworkInterface,
-) -> Result<Box<dyn DataLinkReceiver>, GetInterfaceErrorKind> {
+) -> Result<Box<dyn DataLinkReceiver>, GetInterfaceError> {
let config = Config {
read_timeout: Some(time::Duration::new(1, 0)),
read_buffer_size: 65536,
@@ -43,15 +43,15 @@ pub(crate) fn get_datalink_channel(
match datalink::channel(interface, config) {
Ok(Ethernet(_tx, rx)) => Ok(rx),
- Ok(_) => Err(GetInterfaceErrorKind::OtherError(format!(
+ Ok(_) => Err(GetInterfaceError::OtherError(format!(
"{}: Unsupported interface type",
interface.name
))),
Err(e) => match e.kind() {
- ErrorKind::PermissionDenied => Err(GetInterfaceErrorKind::PermissionError(
+ ErrorKind::PermissionDenied => Err(GetInterfaceError::PermissionError(
interface.name.to_owned(),
)),
- _ => Err(GetInterfaceErrorKind::OtherError(format!(
+ _ => Err(GetInterfaceError::OtherError(format!(
"{}: {}",
&interface.name, e
))),
@@ -85,7 +85,7 @@ where
I: Iterator<
Item = (
&'a NetworkInterface,
- Result<Box<dyn DataLinkReceiver>, GetInterfaceErrorKind>,
+ Result<Box<dyn DataLinkReceiver>, GetInterfaceError>,
),
>,
{
@@ -97,7 +97,7 @@ where
|acc, (_, elem)| {
if let Some(iface_error) = elem.err() {
match iface_error {
- GetInterfaceErrorKind::PermissionError(interface_name) => {
+ GetInterfaceError::PermissionError(interface_name) => {
if let Some(prev_interface) = acc.permission {
return UserErrors {
permission: Some(format!("{}, {}", prev_interface, interface_name)),
@@ -151,12 +151,12 @@ pub fn get_input(
interface_name: &Option<String>,
resolve: bool,
dns_server: &Option<Ipv4Addr>,
-) -> Result<OsInputOutput, failure::Error> {
+) -> anyhow::Result<OsInputOutput> {
let network_interfaces = if let Some(name) = interface_name {
match get_interface(name) {
Some(interface) => vec![interface],
None => {
- failure::bail!("Cannot find interface {}", name);
+ anyhow::bail!("Cannot find interface {}", name);
// the homebrew formula relies on this wording, please be careful when changing
}
}
@@ -195,10 +195,10 @@ pub fn get_input(
if available_network_frames.is_empty() {
let all_errors = collect_errors(network_frames.clone());
if !all_errors.is_empty() {
- failure::bail!(all_errors);
+ anyhow::bail!(all_errors);
}
- failure::bail!("Failed to find any network interface to listen on.");
+ anyhow::bail!("Failed to find any network interface to listen on.");
}
let keyboard_events = Box::new(TerminalEvents);
@@ -207,7 +207,7 @@ pub fn get_input(
let runtime = Runtime::new()?;
let resolver = match runtime.block_on(dns::Resolver::new(dns_server)) {
Ok(resolver) => resolver,
- Err(err) => failure::bail!(
+ Err(err) => anyhow::bail!(
"Could not initialize the DNS resolver. Are you offline?\n\nReason: {:?}",
err
),