Catch packet decoding errors (#809)

* Catch decoding errors, refs #808

* Catch packet handling errors

* Add missing type
This commit is contained in:
Henri Bergius
2025-08-25 16:59:35 -04:00
committed by GitHub
parent 68ec7ee5d8
commit b87fad23d8

View File

@@ -24,16 +24,34 @@ export const decodePacket = (device: MeshDevice) =>
break;
}
case "packet": {
const decodedMessage = fromBinary(
Protobuf.Mesh.FromRadioSchema,
chunk.data,
);
let decodedMessage: Protobuf.Mesh.FromRadio;
try {
decodedMessage = fromBinary(
Protobuf.Mesh.FromRadioSchema,
chunk.data,
);
} catch (e) {
device.log.error(
Types.Emitter[Types.Emitter.HandleFromRadio],
"⚠️ Received undecodable packet",
e,
);
break;
}
device.events.onFromRadio.dispatch(decodedMessage);
/** @todo Add map here when `all=true` gets fixed. */
switch (decodedMessage.payloadVariant.case) {
case "packet": {
device.handleMeshPacket(decodedMessage.payloadVariant.value);
try {
device.handleMeshPacket(decodedMessage.payloadVariant.value);
} catch (e) {
device.log.error(
Types.Emitter[Types.Emitter.HandleFromRadio],
"⚠️ Unable to handle mesh packet",
e,
);
}
break;
}