From b2f5bf1d663fb2e191a759b5d195e77a352d4b99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20Monda?= Date: Tue, 29 Mar 2016 00:34:49 +0200 Subject: [PATCH] Throw consistent error messages. --- model/KeyActionNone.ts | 11 ++++++----- model/KeystrokeAction.ts | 14 +++++++------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/model/KeyActionNone.ts b/model/KeyActionNone.ts index 6993182b..fd57cf78 100644 --- a/model/KeyActionNone.ts +++ b/model/KeyActionNone.ts @@ -2,13 +2,14 @@ /// class KeyActionNone extends KeyAction implements Serializable { + static actionTypeString = 'none'; static keyActionNoneId = 0; static keyActionNoneParam = 0; fromJsObject(jsObject: any): KeyActionNone { - if (jsObject.actionType !== 'none') { - throw 'KeyActionNone: The actionType is not "none"'; + if (jsObject.keyActionType !== KeyActionNone.actionTypeString) { + throw 'Invalid KeyActionNone.keyActionType: "${jsObject.keyActionType}"'; } return this; } @@ -16,12 +17,12 @@ class KeyActionNone extends KeyAction implements Serializable { fromBinary(buffer: UhkBuffer): KeyActionNone { let keyActionId = buffer.readUInt8(); if (keyActionId !== KeyActionNone.keyActionNoneId) { - throw 'KeyActionNone: id is ${keyActionId} instead of ${KeyActionNone.keyActionNoneId}'; + throw 'Invalid KeyActionNone.id: ${keyActionId}'; } let keyActionParam = buffer.readUInt8(); if (keyActionParam !== KeyActionNone.keyActionNoneParam) { - throw 'KeyActionNone: The param is ${keyActionParam} instead of ${KeyActionNone.keyActionNoneParam}'; + throw 'Invalid KeyActionNone.param: ${keyActionParam}'; } return this; @@ -29,7 +30,7 @@ class KeyActionNone extends KeyAction implements Serializable { toJsObject(): any { return { - actionType: 'none' + keyActionType: KeyActionNone.actionTypeString }; } diff --git a/model/KeystrokeAction.ts b/model/KeystrokeAction.ts index b9592264..8a8d24ae 100644 --- a/model/KeystrokeAction.ts +++ b/model/KeystrokeAction.ts @@ -16,7 +16,7 @@ class KeystrokeAction extends KeyAction implements Serializable set scancode(value) { if (!KeystrokeAction.isScancodeValid(value)) { - throw 'Scancode ${scancode} is invalid!'; + throw 'Invalid KeystrokeAction.scancode: ${scancode}'; } this._scancode = value; } @@ -32,6 +32,12 @@ class KeystrokeAction extends KeyAction implements Serializable return this; } + fromBinary(buffer: UhkBuffer): KeystrokeAction { + this.scancode = buffer.readUInt8(); + this.modifierMask = buffer.readUInt8(); + return this; + } + toJsObject(): any { return { keyActionType: KeystrokeAction.actionTypeString, @@ -40,12 +46,6 @@ class KeystrokeAction extends KeyAction implements Serializable }; } - fromBinary(buffer: UhkBuffer): KeystrokeAction { - this.scancode = buffer.readUInt8(); - this.modifierMask = buffer.readUInt8(); - return this; - } - toBinary(buffer: UhkBuffer) { buffer.writeUInt8(this.scancode); buffer.writeUInt8(this.modifierMask);