semtech_udp/packet/
error.rs

1use crate::{Down, Up};
2use thiserror::Error;
3
4#[derive(Error, Debug)]
5pub enum Error {
6    #[error("io error")]
7    Io(#[from] std::io::Error),
8    #[error("json serialization error")]
9    JsonSerialize(#[from] serde_json::error::Error),
10    #[error("packet parse error")]
11    Parse(#[from] ParseError),
12}
13
14#[derive(Error, Debug)]
15pub enum ParseError {
16    #[error("invalid packet length: {0}. Requires at least {1} bytes")]
17    InvalidPacketLength(usize, usize),
18    #[error("invalid GWMP version: {0}")]
19    InvalidProtocolVersion(u8),
20    #[error("invalid GWMP frame identifier: {0}")]
21    InvalidIdentifier(u8),
22    #[error("utf8 error")]
23    Utf8(#[from] std::str::Utf8Error),
24    #[error("invalid Json string for {identifier} frame: {json_str}. JsonError: {json_error}")]
25    InvalidJson {
26        identifier: crate::Identifier,
27        json_str: String,
28        json_error: serde_json::Error,
29    },
30    #[error("Received downlink when expecting uplinks only")]
31    UnexpectedDownlink(Down),
32    #[error("Received uplink when expecting downlinks only")]
33    UnexpectedUplink(Box<Up>),
34}