Add better error logging

This commit is contained in:
2026-01-16 22:17:13 +01:00
parent 40fa67ecea
commit d30a261e74
2 changed files with 45 additions and 8 deletions

View File

@@ -1,5 +1,6 @@
use crate::{Protocol300Message, message};
use thiserror::Error;
use log::error;
extern crate alloc;
use alloc::vec;
@@ -34,7 +35,12 @@ impl Protocol300Transmission {
[0x15] => Ok(Self::Nack),
[0x16, 0x00, 0x00] => Ok(Self::Init),
[0x41, ..] => Ok(Self::Message(Protocol300Message::try_from_bytes(bytes)?)),
_ => Err(FromBytesError::InvalidByte),
_ => {
error!("Failed to parse Protocol300 transmission: invalid byte sequence (length: {}, first byte: 0x{:02X?})",
bytes.len(),
bytes.first().unwrap_or(&0x00));
Err(FromBytesError::InvalidByte)
},
}
}
@@ -143,4 +149,4 @@ mod tests {
};
assert_eq!(Protocol300Transmission::Message(message).to_bytes(), &[0x41, 0x09, 0x01, 0x01, 0x55, 0x25, 0x04, 0x07, 0x01, 0x27, 0x11, 0xC9]);
}
}
}