From 6146f91ed3c5cd0aac0b2d2889607ff71f71511b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Pol=C3=A1=C4=8Dek?= Date: Thu, 23 May 2024 20:40:22 +0200 Subject: [PATCH] Make from_msh_status a pure Rust function --- src/logs.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/logs.rs b/src/logs.rs index 21a6fc9..0b3ad46 100644 --- a/src/logs.rs +++ b/src/logs.rs @@ -5,7 +5,6 @@ use meshtastic::protobufs::{telemetry, Data, ServiceEnvelope, Telemetry}; use meshtastic::protobufs::{MeshPacket, PortNum, Position as PositionProto}; use meshtastic::Message as MeshtaticMessage; use prost_wkt_types::Timestamp; -use pyo3::exceptions::PyValueError; use pyo3::prelude::*; use std::collections::HashMap; use std::fmt; @@ -328,9 +327,8 @@ impl MshLogMessage { now: DateTime, dns: &HashMap, recv_position: Option, - ) -> PyResult> { - let service_envelope = ServiceEnvelope::decode(payload) - .map_err(|e| PyValueError::new_err(format!("Cannot decode proto: {e}")))?; + ) -> Result, std::io::Error> { + let service_envelope = ServiceEnvelope::decode(payload)?; match service_envelope.packet { Some(MeshPacket { payload_variant: Some(PayloadVariant::Decoded(data)), @@ -354,14 +352,13 @@ impl MshLogMessage { RssiSnr::new(rx_rssi, rx_snr), recv_position, ) - .map_err(|_| PyValueError::new_err("Cannot parse inner proto")) } Some(MeshPacket { payload_variant: Some(PayloadVariant::Encrypted(_)), .. - }) => Err(PyValueError::new_err( - "Encrypted message, disable encryption in MQTT!", - )), + }) => Err( + prost::DecodeError::new("Encrypted message, disable encryption in MQTT!").into(), + ), _ => Ok(None), } }