Skip to content

Commit

Permalink
Merge pull request #25 from hirosystems/fix/remove-input-from-error-m…
Browse files Browse the repository at this point in the history
…essages

fix: remove input from error messages
  • Loading branch information
He1DAr authored Jul 5, 2024
2 parents 9e105a0 + 8e09026 commit eeca42a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
dist
.idea
10 changes: 5 additions & 5 deletions src/helpers/values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
}
}

Expand All @@ -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');
}
Expand All @@ -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)) {
Expand Down
6 changes: 3 additions & 3 deletions src/postgres/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ 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) {
return '\\x';
} 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');
Expand Down

0 comments on commit eeca42a

Please sign in to comment.