From 6fd28effe5b386614dc87d8230037524db3357e0 Mon Sep 17 00:00:00 2001 From: clerie Date: Mon, 23 Dec 2024 17:35:43 +0100 Subject: [PATCH] Give more context to errors in improv packet handling --- src/improv.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/improv.rs b/src/improv.rs index 6cf2b4a..c657c4c 100644 --- a/src/improv.rs +++ b/src/improv.rs @@ -371,7 +371,7 @@ impl ImprovDataFromPacket for RPCResultPacket { // load string and append to results let string_bytes = &raw_packet.data[current_string_begin..current_string_end+1]; - let string = std::str::from_utf8(string_bytes).unwrap().to_string(); + let string = std::str::from_utf8(string_bytes).context("Failed to convert response to UTF-8 string")?.to_string(); results.push(string); // next data position @@ -379,7 +379,7 @@ impl ImprovDataFromPacket for RPCResultPacket { } return Ok(Self { - command_responded_to: RPCCommand::try_from(&raw_packet.data[0]).unwrap(), + command_responded_to: RPCCommand::try_from(&raw_packet.data[0]).context("Failed to determine RPC command this packet responds to")?, results: results, }) }