From: Chris Duncan Date: Tue, 30 Jun 2026 20:58:27 +0000 (-0700) Subject: Fix error messages. X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=1a1c3ac5e64c408137a2cb22e93853ff7dc6ee4f;p=libnemo.git Fix error messages. --- diff --git a/src/lib/convert/hex.ts b/src/lib/convert/hex.ts index b356de4..92844ad 100644 --- a/src/lib/convert/hex.ts +++ b/src/lib/convert/hex.ts @@ -3,7 +3,8 @@ export const hex = Object.freeze({ /** - * Convert a hexadecimal string to an ArrayBuffer. + * Convert a hexadecimal string to an ArrayBuffer. The result must be at least + * one byte and no more than 4 GiB. * * @param {string} hex - Hexadecimal number string to convert * @param {number} [padding=1] - Minimum length of the resulting array padded as necessary with starting 0x00 bytes @@ -23,15 +24,15 @@ export const hex = Object.freeze({ */ toBytes (hex: string, padding: number = 1): Uint8Array { if (typeof hex !== 'string' || !/^[0-9a-f]+$/i.test(hex)) { - throw new TypeError('Invalid string when converting hex to array', { cause: hex }) + throw new TypeError('Invalid string when converting hex to bytes', { cause: hex }) } if (typeof padding !== 'number' || padding < 1 || padding > 0xffffffff) { - throw new TypeError('Invalid padding when converting hex to array', { cause: padding }) + throw new TypeError('Invalid padding when converting hex to bytes', { cause: padding }) } if (hex.length & 1) hex = `0${hex}` const hexArray = hex.match(/.{2}/g) if (hexArray == null) { - throw new RangeError('Invalid hex string when converting to array', { cause: hexArray }) + throw new RangeError('Error converting hex string to bytes', { cause: hexArray }) } const diff = padding - hexArray.length const offset = diff & ~(diff >> 31)