From 4d4ecd128985206290cdad7f9899e90b3c38e8c4 Mon Sep 17 00:00:00 2001 From: Nils Andreas Svee Date: Thu, 29 Sep 2022 00:25:14 +0200 Subject: [PATCH] Improve error handling --- src/netlink.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/netlink.rs b/src/netlink.rs index 3d5cc03..939e30b 100644 --- a/src/netlink.rs +++ b/src/netlink.rs @@ -106,7 +106,7 @@ impl Netlink { } // we shouldn't reach here - Ok(-1) + Err(Box::new(NlError::msg("Netlink error retrieving link"))) } pub fn get_interface_stats(ifname: &str) -> Result> { @@ -205,13 +205,13 @@ impl Netlink { } pub fn set_qdisc_rate(qdisc: Qdisc, bandwidth_kbit: u64) -> Result<(), Box> { - let mut socket = NlSocketHandle::connect(NlFamily::Route, None, &[]).unwrap(); + let mut socket = NlSocketHandle::connect(NlFamily::Route, None, &[])?; let bandwidth = bandwidth_kbit * 1000 / 8; let mut attrs = RtBuffer::new(); - let attr_type = Rtattr::new(None, Tca::Kind, "cake").unwrap(); - let mut attr_options = Rtattr::new(None, Tca::Options, Buffer::from(Vec::new())).unwrap(); + let attr_type = Rtattr::new(None, Tca::Kind, "cake")?; + let mut attr_options = Rtattr::new(None, Tca::Options, Buffer::from(Vec::new()))?; attr_options.add_nested_attribute(&Rtattr::new( None, TcaCake::BaseRate64 as u16,