Skip to content

Commit

Permalink
chore(shared): Replace new line with space character in message of Cl…
Browse files Browse the repository at this point in the history
…erkRuntimeError (#4579)
  • Loading branch information
panteliselef authored Nov 15, 2024
1 parent 5bd65aa commit 02b9ae0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .changeset/gentle-insects-shave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
8 changes: 4 additions & 4 deletions packages/shared/src/__tests__/error.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,22 @@ describe('ClerkRuntimeError', () => {
it('throws the correct error message', () => {
expect(() => {
throw clerkRuntimeError;
}).toThrow(/^🔒 Clerk:\ntest\n\n\(Code: "test_code"\)/);
}).toThrow(/^🔒 Clerk: test\n\n\(code="test_code"\)/);
});

it('throws the correct error message without duplicate prefixes', () => {
expect(() => {
throw new ClerkRuntimeError('🔒 Clerk: test', { code: 'test_code' });
}).toThrow(/^🔒 Clerk:\ntest\n\n\(Code: "test_code"\)/);
}).toThrow(/^🔒 Clerk: test\n\n\(code="test_code"\)/);
});

it('properties are populated correctly', () => {
expect(clerkRuntimeError.name).toEqual('ClerkRuntimeError');
expect(clerkRuntimeError.code).toEqual('test_code');
expect(clerkRuntimeError.message).toMatch(/🔒 Clerk:\ntest\n\n\(Code: "test_code"\)/);
expect(clerkRuntimeError.message).toMatch(/🔒 Clerk: test\n\n\(code="test_code"\)/);
expect(clerkRuntimeError.clerkRuntimeError).toBe(true);
expect(clerkRuntimeError.toString()).toMatch(
/^\[ClerkRuntimeError\]\nMessage:🔒 Clerk:\ntest\n\n\(Code: "test_code"\)/,
/^\[ClerkRuntimeError\]\nMessage:🔒 Clerk: test\n\n\(code="test_code"\)/,
);
});

Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export class ClerkRuntimeError extends Error {
const prefix = '🔒 Clerk:';
const regex = new RegExp(prefix.replace(' ', '\\s*'), 'i');
const sanitized = message.replace(regex, '');
const _message = `${prefix}\n${sanitized.trim()}\n\n(Code: "${code}")\n`;
const _message = `${prefix} ${sanitized.trim()}\n\n(code="${code}")\n`;
super(_message);

Object.setPrototypeOf(this, ClerkRuntimeError.prototype);
Expand Down

0 comments on commit 02b9ae0

Please sign in to comment.