diff options
author | Aram Drevekenin <aram@poor.dev> | 2019-10-17 17:57:55 +0200 |
---|---|---|
committer | Aram Drevekenin <aram@poor.dev> | 2019-10-17 17:57:55 +0200 |
commit | 50b4e6471eef5400158071b156b4a3faeba29063 (patch) | |
tree | cf5d9a0511fc90e8dd89734bdcfe6ee60db68556 | |
parent | 59c96d4e23e8d92849c844ab5cdfaf3f23eefa52 (diff) |
fix(linux): better error when not enough permissions
-rw-r--r-- | src/os/linux.rs | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/os/linux.rs b/src/os/linux.rs index 642de38..cc2d883 100644 --- a/src/os/linux.rs +++ b/src/os/linux.rs @@ -27,14 +27,14 @@ impl Iterator for KeyboardEvents { } } -fn get_datalink_channel(interface: &NetworkInterface) -> Box<DataLinkReceiver> { +fn get_datalink_channel(interface: &NetworkInterface) -> Result<Box<DataLinkReceiver>, failure::Error> { let mut config = Config::default(); config.read_timeout = Some(time::Duration::new(0, 1)); match datalink::channel(interface, config) { - Ok(Ethernet(_tx, rx)) => rx, - Ok(_) => panic!("Unhandled channel type"), - Err(e) => panic!( - "An error occurred when creating the datalink channel: {}", + Ok(Ethernet(_tx, rx)) => Ok(rx), + Ok(_) => failure::bail!("Unknown interface type"), + Err(e) => failure::bail!( + "Failed to listen to network interface: {}", e ), } @@ -118,7 +118,7 @@ pub fn get_input(opt: Opt) -> Result<OsInput, failure::Error> { failure::bail!("Cannot find interface {}", opt.interface); } }; - let network_frames = get_datalink_channel(&network_interface); + let network_frames = get_datalink_channel(&network_interface)?; let lookup_addr = Box::new(lookup_addr); let (on_winch, cleanup) = sigwinch(); |