Skip to content

Commit

Permalink
Remove console error prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
amortemousque committed Jun 7, 2023
1 parent 512137b commit 695d4bd
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
18 changes: 9 additions & 9 deletions packages/core/src/domain/console/consoleObservable.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -37,7 +37,7 @@ import { initConsoleObservable } from './consoleObservable'

expect(consoleLog).toEqual(
jasmine.objectContaining({
message: `${prefix}foo bar`,
message: 'foo bar',
api,
})
)
Expand All @@ -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', () => {
Expand Down
4 changes: 1 addition & 3 deletions packages/core/src/domain/console/consoleObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,14 @@ 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

if (api === ConsoleApiName.error) {
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 {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/scenario/logs.scenario.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/scenario/rum/errors.scenario.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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}/:`],
Expand Down

0 comments on commit 695d4bd

Please sign in to comment.