From 3c056a7255120996002bb06c1082515fcab59bc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20Monda?= Date: Sat, 19 May 2018 13:38:16 +0200 Subject: [PATCH] Display "Invalid hardware configuration" when the hardware configuration area is uninitialized instead of a general error message. Improves #623. --- .../config-items/hardware-configuration.ts | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/packages/uhk-common/src/config-serializer/config-items/hardware-configuration.ts b/packages/uhk-common/src/config-serializer/config-items/hardware-configuration.ts index 12a1184a..0e41524b 100644 --- a/packages/uhk-common/src/config-serializer/config-items/hardware-configuration.ts +++ b/packages/uhk-common/src/config-serializer/config-items/hardware-configuration.ts @@ -41,16 +41,20 @@ export class HardwareConfiguration { } fromBinary(buffer: UhkBuffer): HardwareConfiguration { - this.signature = buffer.readString(); - this.majorVersion = buffer.readUInt8(); - this.minorVersion = buffer.readUInt8(); - this.patchVersion = buffer.readUInt8(); - this.brandId = buffer.readUInt8(); - this.deviceId = buffer.readUInt8(); - this.uniqueId = buffer.readUInt32(); - this.isVendorModeOn = buffer.readBoolean(); - this.isIso = buffer.readBoolean(); - return this; + try { + this.signature = buffer.readString(); + this.majorVersion = buffer.readUInt8(); + this.minorVersion = buffer.readUInt8(); + this.patchVersion = buffer.readUInt8(); + this.brandId = buffer.readUInt8(); + this.deviceId = buffer.readUInt8(); + this.uniqueId = buffer.readUInt32(); + this.isVendorModeOn = buffer.readBoolean(); + this.isIso = buffer.readBoolean(); + return this; + } catch (e) { + throw new Error('Invalid hardware configuration'); + } } toJsonObject(): any {