diff --git a/eslint.config.mjs b/eslint.config.mjs index 1ace33295af..809f9feb0a4 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -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', diff --git a/packages/mcumgr/src/util/cbor.ts b/packages/mcumgr/src/util/cbor.ts index de281ebd357..33f3aa47837 100644 --- a/packages/mcumgr/src/util/cbor.ts +++ b/packages/mcumgr/src/util/cbor.ts @@ -245,7 +245,7 @@ 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(); @@ -253,7 +253,7 @@ export function decode(data: ArrayBuffer | SharedArrayBuffer, tagger?: Function, 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; } @@ -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: { @@ -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; } diff --git a/packages/uhk-common/src/config-serializer/assert.ts b/packages/uhk-common/src/config-serializer/assert.ts index da685b2689f..afe124f97ef 100644 --- a/packages/uhk-common/src/config-serializer/assert.ts +++ b/packages/uhk-common/src/config-serializer/assert.ts @@ -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; } @@ -82,7 +82,7 @@ export function assertEnum(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; } diff --git a/packages/uhk-common/src/config-serializer/config-items/key-action/helper.ts b/packages/uhk-common/src/config-serializer/config-items/key-action/helper.ts index 5f9a9152c37..2d0d2ee6bd6 100644 --- a/packages/uhk-common/src/config-serializer/config-items/key-action/helper.ts +++ b/packages/uhk-common/src/config-serializer/config-items/key-action/helper.ts @@ -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}`); } } @@ -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}"`); } } } diff --git a/packages/uhk-common/src/config-serializer/config-items/key-action/key-action.ts b/packages/uhk-common/src/config-serializer/config-items/key-action/key-action.ts index 4cf24cc3d41..76f40c48ad6 100644 --- a/packages/uhk-common/src/config-serializer/config-items/key-action/key-action.ts +++ b/packages/uhk-common/src/config-serializer/config-items/key-action/key-action.ts @@ -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}`); } } @@ -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; } diff --git a/packages/uhk-common/src/config-serializer/config-items/macro-action/helper.ts b/packages/uhk-common/src/config-serializer/config-items/macro-action/helper.ts index b2d1d36182d..41bd781fc23 100644 --- a/packages/uhk-common/src/config-serializer/config-items/macro-action/helper.ts +++ b/packages/uhk-common/src/config-serializer/config-items/macro-action/helper.ts @@ -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}`); } } @@ -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}"`); } } } diff --git a/packages/uhk-common/src/config-serializer/config-items/macro-action/macro-action.ts b/packages/uhk-common/src/config-serializer/config-items/macro-action/macro-action.ts index d65f7cdc7bc..d9ca3c5f070 100644 --- a/packages/uhk-common/src/config-serializer/config-items/macro-action/macro-action.ts +++ b/packages/uhk-common/src/config-serializer/config-items/macro-action/macro-action.ts @@ -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}`); } } @@ -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; } diff --git a/packages/uhk-common/src/config-serializer/uhk-buffer.ts b/packages/uhk-common/src/config-serializer/uhk-buffer.ts index bd813932941..4a91773a46d 100644 --- a/packages/uhk-common/src/config-serializer/uhk-buffer.ts +++ b/packages/uhk-common/src/config-serializer/uhk-buffer.ts @@ -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);