Throw consistent error messages.
This commit is contained in:
@@ -2,13 +2,14 @@
|
||||
/// <reference path="Serializable.ts" />
|
||||
|
||||
class KeyActionNone extends KeyAction implements Serializable<KeyActionNone> {
|
||||
|
||||
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<KeyActionNone> {
|
||||
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<KeyActionNone> {
|
||||
|
||||
toJsObject(): any {
|
||||
return {
|
||||
actionType: 'none'
|
||||
keyActionType: KeyActionNone.actionTypeString
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ class KeystrokeAction extends KeyAction implements Serializable<KeystrokeAction>
|
||||
|
||||
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<KeystrokeAction>
|
||||
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<KeystrokeAction>
|
||||
};
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user