From 1700bf5531ab7548a80842bb53dc91634abc97d4 Mon Sep 17 00:00:00 2001 From: clerie Date: Wed, 25 Dec 2024 17:38:21 +0100 Subject: [PATCH] Add context for serial device exceptions --- src/serial.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/serial.rs b/src/serial.rs index 5b43eee..b4ff837 100644 --- a/src/serial.rs +++ b/src/serial.rs @@ -47,7 +47,7 @@ pub struct SerialInterface { impl SerialInterface { pub fn new(path: &str, baud_rate: u32) -> Result { - let interface = tokio_serial::new(path, baud_rate).open().unwrap(); + let interface = tokio_serial::new(path, baud_rate).open().context("Failed to open serial device")?; return Ok(Self { interface: interface, @@ -84,7 +84,7 @@ impl SerialInterface { debug!("Received bytes: \n{}\n{}", hex::encode(&buffer), to_ascii_debug(&buffer)); } - let improv_packet_offset = find_begin_of_improv_packet(&buffer).unwrap(); + let improv_packet_offset = find_begin_of_improv_packet(&buffer).context("Failed to find improv header in received bytes from serial device")?; let improv_packet_end = improv_packet_offset + 10 + >::into(buffer[improv_packet_offset+8]);