From 02b9ae0a47871adccfefb247878691b72e25e929 Mon Sep 17 00:00:00 2001 From: panteliselef Date: Fri, 15 Nov 2024 11:34:33 -0500 Subject: [PATCH] chore(shared): Replace new line with space character in message of ClerkRuntimeError (#4579) --- .changeset/gentle-insects-shave.md | 2 ++ packages/shared/src/__tests__/error.test.ts | 8 ++++---- packages/shared/src/error.ts | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) create mode 100644 .changeset/gentle-insects-shave.md diff --git a/.changeset/gentle-insects-shave.md b/.changeset/gentle-insects-shave.md new file mode 100644 index 0000000000..a845151cc8 --- /dev/null +++ b/.changeset/gentle-insects-shave.md @@ -0,0 +1,2 @@ +--- +--- diff --git a/packages/shared/src/__tests__/error.test.ts b/packages/shared/src/__tests__/error.test.ts index 31fd8b2a53..85be2d7d2d 100644 --- a/packages/shared/src/__tests__/error.test.ts +++ b/packages/shared/src/__tests__/error.test.ts @@ -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"\)/, ); }); diff --git a/packages/shared/src/error.ts b/packages/shared/src/error.ts index e427a5e72f..335f11c577 100644 --- a/packages/shared/src/error.ts +++ b/packages/shared/src/error.ts @@ -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);