Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export const typescriptRules = {
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/no-wrapper-object-types': 'off',
'@typescript-eslint/only-throw-error': 'off',
'@typescript-eslint/require-await': 'off',
'@typescript-eslint/restrict-template-expressions': 'off',
'@typescript-eslint/unbound-method': 'off',
Expand Down
8 changes: 4 additions & 4 deletions packages/mcumgr/src/util/cbor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,15 +245,15 @@ export function decode(data: ArrayBuffer | SharedArrayBuffer, tagger?: Function,
return readUint64();
if (additionalInformation === 31)
return -1;
throw "Invalid length encoding";
throw new Error("Invalid length encoding");
}
function readIndefiniteStringLength(majorType: number): number {
const initialByte = readUint8();
if (initialByte === 0xff)
return -1;
const length = readLength(initialByte & 0x1f);
if (length < 0 || (initialByte >> 5) !== majorType)
throw "Invalid indefinite length element";
throw new Error("Invalid indefinite length element");
return length;
}

Expand Down Expand Up @@ -309,7 +309,7 @@ export function decode(data: ArrayBuffer | SharedArrayBuffer, tagger?: Function,

length = readLength(additionalInformation);
if (length < 0 && (majorType < 2 || 6 < majorType))
throw "Invalid length";
throw new Error("Invalid length");

switch (majorType) {
case 0: {
Expand Down Expand Up @@ -395,6 +395,6 @@ export function decode(data: ArrayBuffer | SharedArrayBuffer, tagger?: Function,

const ret = decodeItem();
if (offset !== data.byteLength)
throw "Remaining bytes";
throw new Error("Remaining bytes");
return ret;
}
6 changes: 3 additions & 3 deletions packages/uhk-common/src/config-serializer/assert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ function assertInteger(target: any, key: string, min: number, max: number) {
function setter(newVal: any) {
if (this[priv] !== newVal) {
if (newVal < min || newVal > max) {
throw `${target.constructor.name}.${key}: ` +
`Integer ${newVal} is outside the valid [${min}, ${max}] interval`;
throw new Error(`${target.constructor.name}.${key}: ` +
`Integer ${newVal} is outside the valid [${min}, ${max}] interval`);
}
this[priv] = newVal;
}
Expand Down Expand Up @@ -82,7 +82,7 @@ export function assertEnum<E>(enumerated: E) {

if (this[priv] !== newVal) {
if (enumerated[newVal] === undefined) {
throw `${target.constructor.name}.${key}: ${newVal} is not enum`;
throw new Error(`${target.constructor.name}.${key}: ${newVal} is not enum`);
}
this[priv] = newVal;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class Helper {
case KeyActionId.PlayMacroAction:
return new PlayMacroAction().fromBinary(buffer, serialisationInfo, macros);
default:
throw `Invalid KeyAction first byte: ${keyActionFirstByte}`;
throw new Error(`Invalid KeyAction first byte: ${keyActionFirstByte}`);
}
}

Expand Down Expand Up @@ -176,7 +176,7 @@ export class Helper {
case keyActionType.NoneBlockAction:
return new NoneBlockAction().fromJsonObject(keyAction, serialisationInfo);
default:
throw `Invalid KeyAction.keyActionType: "${keyAction.keyActionType}"`;
throw new Error(`Invalid KeyAction.keyActionType: "${keyAction.keyActionType}"`);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export abstract class KeyAction implements RgbColorInterface {
const keyActionClassname: string = this.getName();
const keyActionTypeString: string = keyActionType[keyActionClassname];
if (jsObject.keyActionType !== keyActionTypeString) {
throw `Invalid ${keyActionClassname}.keyActionType: ${jsObject.keyActionType}`;
throw new Error(`Invalid ${keyActionClassname}.keyActionType: ${jsObject.keyActionType}`);
}
}

Expand All @@ -71,10 +71,10 @@ export abstract class KeyAction implements RgbColorInterface {
const keyActionId: number = KeyActionId[classname];
if (keyActionId === KeyActionId.KeystrokeAction) {
if (readKeyActionId < KeyActionId.KeystrokeAction || readKeyActionId > KeyActionId.LastKeystrokeAction) {
throw `Invalid ${classname} first byte: ${readKeyActionId}`;
throw new Error(`Invalid ${classname} first byte: ${readKeyActionId}`);
}
} else if (readKeyActionId !== keyActionId) {
throw `Invalid ${classname} first byte: ${readKeyActionId}`;
throw new Error(`Invalid ${classname} first byte: ${readKeyActionId}`);
}
return readKeyActionId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class Helper {
case MacroActionId.CommandMacroAction:
return new CommandMacroAction().fromBinary(buffer, serialisationInfo);
default:
throw `Invalid MacroAction first byte: ${macroActionFirstByte}`;
throw new Error(`Invalid MacroAction first byte: ${macroActionFirstByte}`);
}
}

Expand Down Expand Up @@ -87,7 +87,7 @@ export class Helper {
case macroActionType.CommandMacroAction:
return new CommandMacroAction().fromJsonObject(macroAction, serialisationInfo);
default:
throw `Invalid MacroAction.macroActionType: "${macroAction.macroActionType}"`;
throw new Error(`Invalid MacroAction.macroActionType: "${macroAction.macroActionType}"`);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export abstract class MacroAction {
const macroActionClassname = this.getName();
const macroActionTypeString = macroActionType[macroActionClassname];
if (jsObject.macroActionType !== macroActionTypeString) {
throw `Invalid ${macroActionClassname}.macroActionType: ${jsObject.macroActionType}`;
throw new Error(`Invalid ${macroActionClassname}.macroActionType: ${jsObject.macroActionType}`);
}
}

Expand All @@ -62,15 +62,15 @@ export abstract class MacroAction {
const macroActionId: MacroActionId = MacroActionId[classname];
if (macroActionId === MacroActionId.KeyMacroAction) {
if (readMacroActionId < MacroActionId.KeyMacroAction || readMacroActionId > MacroActionId.LastKeyMacroAction) {
throw `Invalid ${classname} first byte: ${readMacroActionId}`;
throw new Error(`Invalid ${classname} first byte: ${readMacroActionId}`);
}
} else if (macroActionId === MacroActionId.MouseButtonMacroAction) {
if (readMacroActionId < MacroActionId.MouseButtonMacroAction ||
readMacroActionId > MacroActionId.LastMouseButtonMacroAction) {
throw `Invalid ${classname} first byte: ${readMacroActionId}`;
throw new Error(`Invalid ${classname} first byte: ${readMacroActionId}`);
}
} else if (readMacroActionId !== macroActionId) {
throw `Invalid ${classname} first byte: ${readMacroActionId}`;
throw new Error(`Invalid ${classname} first byte: ${readMacroActionId}`);
}
return readMacroActionId;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/uhk-common/src/config-serializer/uhk-buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ export class UhkBuffer {
const stringByteLength = Buffer.byteLength(str, UhkBuffer.stringEncoding);

if (stringByteLength > UhkBuffer.maxCompactLength) {
throw `Cannot serialize string: ${stringByteLength} bytes is larger
than the maximum allowed length of ${UhkBuffer.maxCompactLength} bytes`;
throw new Error(`Cannot serialize string: ${stringByteLength} bytes is larger
than the maximum allowed length of ${UhkBuffer.maxCompactLength} bytes`);
}

this.writeCompactLength(stringByteLength);
Expand Down
Loading