Throw consistent error messages.
This commit is contained in:
@@ -2,13 +2,14 @@
|
|||||||
/// <reference path="Serializable.ts" />
|
/// <reference path="Serializable.ts" />
|
||||||
|
|
||||||
class KeyActionNone extends KeyAction implements Serializable<KeyActionNone> {
|
class KeyActionNone extends KeyAction implements Serializable<KeyActionNone> {
|
||||||
|
|
||||||
static actionTypeString = 'none';
|
static actionTypeString = 'none';
|
||||||
static keyActionNoneId = 0;
|
static keyActionNoneId = 0;
|
||||||
static keyActionNoneParam = 0;
|
static keyActionNoneParam = 0;
|
||||||
|
|
||||||
fromJsObject(jsObject: any): KeyActionNone {
|
fromJsObject(jsObject: any): KeyActionNone {
|
||||||
if (jsObject.actionType !== 'none') {
|
if (jsObject.keyActionType !== KeyActionNone.actionTypeString) {
|
||||||
throw 'KeyActionNone: The actionType is not "none"';
|
throw 'Invalid KeyActionNone.keyActionType: "${jsObject.keyActionType}"';
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -16,12 +17,12 @@ class KeyActionNone extends KeyAction implements Serializable<KeyActionNone> {
|
|||||||
fromBinary(buffer: UhkBuffer): KeyActionNone {
|
fromBinary(buffer: UhkBuffer): KeyActionNone {
|
||||||
let keyActionId = buffer.readUInt8();
|
let keyActionId = buffer.readUInt8();
|
||||||
if (keyActionId !== KeyActionNone.keyActionNoneId) {
|
if (keyActionId !== KeyActionNone.keyActionNoneId) {
|
||||||
throw 'KeyActionNone: id is ${keyActionId} instead of ${KeyActionNone.keyActionNoneId}';
|
throw 'Invalid KeyActionNone.id: ${keyActionId}';
|
||||||
}
|
}
|
||||||
|
|
||||||
let keyActionParam = buffer.readUInt8();
|
let keyActionParam = buffer.readUInt8();
|
||||||
if (keyActionParam !== KeyActionNone.keyActionNoneParam) {
|
if (keyActionParam !== KeyActionNone.keyActionNoneParam) {
|
||||||
throw 'KeyActionNone: The param is ${keyActionParam} instead of ${KeyActionNone.keyActionNoneParam}';
|
throw 'Invalid KeyActionNone.param: ${keyActionParam}';
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
@@ -29,7 +30,7 @@ class KeyActionNone extends KeyAction implements Serializable<KeyActionNone> {
|
|||||||
|
|
||||||
toJsObject(): any {
|
toJsObject(): any {
|
||||||
return {
|
return {
|
||||||
actionType: 'none'
|
keyActionType: KeyActionNone.actionTypeString
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ class KeystrokeAction extends KeyAction implements Serializable<KeystrokeAction>
|
|||||||
|
|
||||||
set scancode(value) {
|
set scancode(value) {
|
||||||
if (!KeystrokeAction.isScancodeValid(value)) {
|
if (!KeystrokeAction.isScancodeValid(value)) {
|
||||||
throw 'Scancode ${scancode} is invalid!';
|
throw 'Invalid KeystrokeAction.scancode: ${scancode}';
|
||||||
}
|
}
|
||||||
this._scancode = value;
|
this._scancode = value;
|
||||||
}
|
}
|
||||||
@@ -32,6 +32,12 @@ class KeystrokeAction extends KeyAction implements Serializable<KeystrokeAction>
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fromBinary(buffer: UhkBuffer): KeystrokeAction {
|
||||||
|
this.scancode = buffer.readUInt8();
|
||||||
|
this.modifierMask = buffer.readUInt8();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
toJsObject(): any {
|
toJsObject(): any {
|
||||||
return {
|
return {
|
||||||
keyActionType: KeystrokeAction.actionTypeString,
|
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) {
|
toBinary(buffer: UhkBuffer) {
|
||||||
buffer.writeUInt8(this.scancode);
|
buffer.writeUInt8(this.scancode);
|
||||||
buffer.writeUInt8(this.modifierMask);
|
buffer.writeUInt8(this.modifierMask);
|
||||||
|
|||||||
Reference in New Issue
Block a user