From 695d4bdb8342385db6201b0ca4684af667f48197 Mon Sep 17 00:00:00 2001 From: Aymeric Date: Wed, 7 Jun 2023 15:59:05 +0200 Subject: [PATCH] Remove console error prefix --- .../domain/console/consoleObservable.spec.ts | 18 +++++++++--------- .../src/domain/console/consoleObservable.ts | 4 +--- test/e2e/scenario/logs.scenario.ts | 2 +- test/e2e/scenario/rum/errors.scenario.ts | 4 ++-- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/packages/core/src/domain/console/consoleObservable.spec.ts b/packages/core/src/domain/console/consoleObservable.spec.ts index 8aeec39631..4064eeaab0 100644 --- a/packages/core/src/domain/console/consoleObservable.spec.ts +++ b/packages/core/src/domain/console/consoleObservable.spec.ts @@ -8,12 +8,12 @@ import { initConsoleObservable } from './consoleObservable' // prettier: avoid formatting issue // cf https://github.com/prettier/prettier/issues/12211 ;[ - { api: ConsoleApiName.log, prefix: '' }, - { api: ConsoleApiName.info, prefix: '' }, - { api: ConsoleApiName.warn, prefix: '' }, - { api: ConsoleApiName.debug, prefix: '' }, - { api: ConsoleApiName.error, prefix: 'console error: ' }, -].forEach(({ api, prefix }) => { + { api: ConsoleApiName.log }, + { api: ConsoleApiName.info }, + { api: ConsoleApiName.warn }, + { api: ConsoleApiName.debug }, + { api: ConsoleApiName.error }, +].forEach(({ api }) => { describe(`console ${api} observable`, () => { let consoleStub: jasmine.Spy let consoleSubscription: Subscription @@ -37,7 +37,7 @@ import { initConsoleObservable } from './consoleObservable' expect(consoleLog).toEqual( jasmine.objectContaining({ - message: `${prefix}foo bar`, + message: 'foo bar', api, }) ) @@ -52,13 +52,13 @@ import { initConsoleObservable } from './consoleObservable' it('should format error instance', () => { console[api](new TypeError('hello')) const consoleLog = notifyLog.calls.mostRecent().args[0] - expect(consoleLog.message).toBe(`${prefix}TypeError: hello`) + expect(consoleLog.message).toBe('TypeError: hello') }) it('should stringify object parameters', () => { console[api]('Hello', { foo: 'bar' }) const consoleLog = notifyLog.calls.mostRecent().args[0] - expect(consoleLog.message).toBe(`${prefix}Hello {\n "foo": "bar"\n}`) + expect(consoleLog.message).toBe('Hello {\n "foo": "bar"\n}') }) it('should allow multiple callers', () => { diff --git a/packages/core/src/domain/console/consoleObservable.ts b/packages/core/src/domain/console/consoleObservable.ts index bbf8f7c027..21c7ecab86 100644 --- a/packages/core/src/domain/console/consoleObservable.ts +++ b/packages/core/src/domain/console/consoleObservable.ts @@ -54,8 +54,7 @@ function createConsoleObservable(api: ConsoleApiName) { } function buildConsoleLog(params: unknown[], api: ConsoleApiName, handlingStack: string): ConsoleLog { - // Todo: remove console error prefix in the next major version - let message = params.map((param) => formatConsoleParameters(param)).join(' ') + const message = params.map((param) => formatConsoleParameters(param)).join(' ') let stack let fingerprint @@ -63,7 +62,6 @@ function buildConsoleLog(params: unknown[], api: ConsoleApiName, handlingStack: const firstErrorParam = find(params, (param: unknown): param is Error => param instanceof Error) stack = firstErrorParam ? toStackTraceString(computeStackTrace(firstErrorParam)) : undefined fingerprint = tryToGetFingerprint(firstErrorParam) - message = `console error: ${message}` } return { diff --git a/test/e2e/scenario/logs.scenario.ts b/test/e2e/scenario/logs.scenario.ts index 171db742dc..c672213290 100644 --- a/test/e2e/scenario/logs.scenario.ts +++ b/test/e2e/scenario/logs.scenario.ts @@ -23,7 +23,7 @@ describe('logs', () => { }) await flushEvents() expect(serverEvents.logs.length).toBe(1) - expect(serverEvents.logs[0].message).toBe('console error: oh snap') + expect(serverEvents.logs[0].message).toBe('oh snap') await withBrowserLogs((browserLogs) => { expect(browserLogs.length).toEqual(1) }) diff --git a/test/e2e/scenario/rum/errors.scenario.ts b/test/e2e/scenario/rum/errors.scenario.ts index 52dd03c1d1..10899b2bb2 100644 --- a/test/e2e/scenario/rum/errors.scenario.ts +++ b/test/e2e/scenario/rum/errors.scenario.ts @@ -30,7 +30,7 @@ describe('rum errors', () => { await flushEvents() expect(serverEvents.rumErrors.length).toBe(1) expectError(serverEvents.rumErrors[0].error, { - message: 'console error: oh snap', + message: 'oh snap', source: 'console', handlingStack: ['Error: ', `handler @ ${baseUrl}/:`], handling: 'handled', @@ -50,7 +50,7 @@ describe('rum errors', () => { await flushEvents() expect(serverEvents.rumErrors.length).toBe(1) expectError(serverEvents.rumErrors[0].error, { - message: 'console error: Foo: Error: oh snap', + message: 'Foo: Error: oh snap', source: 'console', stack: ['Error: oh snap', `at foo @ ${baseUrl}/:`, `handler @ ${baseUrl}/:`], handlingStack: ['Error: ', `handler @ ${baseUrl}/:`],