From 8e090266e30716c15bd46cb3b40c9f4aecfe3ef2 Mon Sep 17 00:00:00 2001 From: He1DAr <97111756+He1DAr@users.noreply.github.com> Date: Fri, 5 Jul 2024 09:50:06 -0400 Subject: [PATCH] Merge pull request #23 from hirosystems/fix/remove-input-from-error-messages fix: remove input from error messages --- .gitignore | 1 + src/helpers/values.ts | 10 +++++----- src/postgres/types.ts | 6 +++--- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index f06235c..82ee25a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules dist +.idea diff --git a/src/helpers/values.ts b/src/helpers/values.ts index cc1a34e..7b8a22e 100644 --- a/src/helpers/values.ts +++ b/src/helpers/values.ts @@ -43,7 +43,7 @@ export function parseBoolean(val: string | undefined | null): boolean { case 'no': return false; default: - throw new Error(`Cannot parse boolean from "${val}"`); + throw new Error(`Cannot parse boolean`); } } @@ -64,10 +64,10 @@ export function hexToBuffer(hex: string): Buffer { return Buffer.alloc(0); } if (!hex.startsWith('0x')) { - throw new Error(`Hex string is missing the "0x" prefix: "${hex}"`); + throw new Error(`Hex string is missing the "0x" prefix`); } if (hex.length % 2 !== 0) { - throw new Error(`Hex string is an odd number of digits: ${hex}`); + throw new Error(`Hex string is an odd number of digits`); } return Buffer.from(hex.substring(2), 'hex'); } @@ -82,10 +82,10 @@ export function coerceToBuffer(hex: string | Buffer | ArrayBufferView): Buffer { hex = hex.substring(2); } if (hex.length % 2 !== 0) { - throw new Error(`Hex string is an odd number of characters: ${hex}`); + throw new Error(`Hex string is an odd number of characters`); } if (!/^[0-9a-fA-F]*$/.test(hex)) { - throw new Error(`Hex string contains non-hexadecimal characters: ${hex}`); + throw new Error(`Hex string contains non-hexadecimal characters`); } return Buffer.from(hex, 'hex'); } else if (Buffer.isBuffer(hex)) { diff --git a/src/postgres/types.ts b/src/postgres/types.ts index 8decdad..4492275 100644 --- a/src/postgres/types.ts +++ b/src/postgres/types.ts @@ -11,7 +11,7 @@ export const PG_TYPE_MAPPINGS = { if (/^(0x|0X)[a-fA-F0-9]*$/.test(x)) { // hex string with "0x" prefix if (x.length % 2 !== 0) { - throw new Error(`Hex string is an odd number of digits: "${x}"`); + throw new Error(`Hex string is an odd number of digits`); } return '\\x' + x.slice(2); } else if (x.length === 0) { @@ -19,11 +19,11 @@ export const PG_TYPE_MAPPINGS = { } else if (/^\\x[a-fA-F0-9]*$/.test(x)) { // hex string with "\x" prefix (already encoded for postgres) if (x.length % 2 !== 0) { - throw new Error(`Hex string is an odd number of digits: "${x}"`); + throw new Error(`Hex string is an odd number of digits`); } return x; } else { - throw new Error(`String value for bytea column does not have 0x prefix: "${x}"`); + throw new Error(`String value for bytea column does not have 0x prefix`); } } else if (Buffer.isBuffer(x)) { return '\\x' + x.toString('hex');