From 7a72ca998fc2a345f0a9ed3f1d92b1ee6da9320a Mon Sep 17 00:00:00 2001 From: Martin Varmuza Date: Mon, 20 May 2024 07:46:25 +0200 Subject: [PATCH] chore(connect): fw-update: add error message when binary is too small --- .../connect/src/core/onCallFirmwareUpdate.ts | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/packages/connect/src/core/onCallFirmwareUpdate.ts b/packages/connect/src/core/onCallFirmwareUpdate.ts index 3977270d8ac..a1b94ebcec3 100644 --- a/packages/connect/src/core/onCallFirmwareUpdate.ts +++ b/packages/connect/src/core/onCallFirmwareUpdate.ts @@ -202,17 +202,27 @@ const getBinaryHelper = ( version: device.firmwareRelease.release.version, btcOnly, intermediaryVersion, - }).then(res => { - postMessage( - createUiMessage(UI.FIRMWARE_PROGRESS, { - device: device.toMessageObject(), - operation: 'downloading', - progress: 100, - }), - ); + }) + .then(res => { + // suspiciously small binary. this typically happens when build does not have git lfs enabled and all + // you download here are some pointers to lfs objects which are around ~132 byteLength + if (res.byteLength < 200) { + throw ERRORS.TypedError('Runtime', 'Firmware binary is too small'); + } - return res; - }); + return res; + }) + .then(res => { + postMessage( + createUiMessage(UI.FIRMWARE_PROGRESS, { + device: device.toMessageObject(), + operation: 'downloading', + progress: 100, + }), + ); + + return res; + }); }; const firmwareCheck = async (