Skip to content

Commit

Permalink
fix: remove input from error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
He1DAr committed Jul 3, 2024
1 parent 5be1111 commit ffc9be2
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 8 deletions.
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/api-toolkit.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions .idea/cody_history.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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 ffc9be2

Please sign in to comment.