From c611be58de378a0432627dea4679a7783e7bace3 Mon Sep 17 00:00:00 2001 From: Adrian Jagielak Date: Wed, 24 Sep 2025 23:52:39 +0200 Subject: [PATCH] Add error handling for invalid FIMP messages --- futurehome/src/fimp/fimp.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/futurehome/src/fimp/fimp.ts b/futurehome/src/fimp/fimp.ts index b0ac807..2d2ed47 100644 --- a/futurehome/src/fimp/fimp.ts +++ b/futurehome/src/fimp/fimp.ts @@ -82,7 +82,24 @@ export async function sendFimpMsg({ }, timeoutMs); const onResponse = (topic: string, buffer: any) => { - const msg = JSON.parse(buffer.toString()); + let bufferToString; + try { + bufferToString = buffer.toString(); + } catch (e) { + log.warn('Invalid message received from hub MQTT broker', e); + return; + } + + let msg; + try { + msg = JSON.parse(bufferToString); + } catch (e) { + log.warn( + `Invalid FIMP message received from hub MQTT broker\nMessage: ${bufferToString}`, + e, + ); + return; + } if (msg.corid === uid) { if (msg.type === 'evt.error.report') {