Throw consistent error messages.

This commit is contained in:
László Monda
2016-03-29 00:34:49 +02:00
parent 0aeec88cb5
commit b2f5bf1d66
2 changed files with 13 additions and 12 deletions

View File

@@ -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
};
}

View File

@@ -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);