diff --git a/packages/core/src/utils/object.ts b/packages/core/src/utils/object.ts index e212b9f3b833..06f80e12d7f7 100644 --- a/packages/core/src/utils/object.ts +++ b/packages/core/src/utils/object.ts @@ -4,7 +4,6 @@ import type { WrappedFunction } from '../types-hoist/wrappedfunction'; import { htmlTreeAsString } from './browser'; import { debug } from './debug-logger'; import { isElement, isError, isEvent, isInstanceOf, isPrimitive } from './is'; -import { truncate } from './string'; /** * Replace a method in an object with a wrapped version of itself. @@ -176,32 +175,11 @@ function getOwnProperties(obj: unknown): { [key: string]: unknown } { * and truncated list that will be used inside the event message. * eg. `Non-error exception captured with keys: foo, bar, baz` */ -export function extractExceptionKeysForMessage(exception: Record, maxLength: number = 40): string { +export function extractExceptionKeysForMessage(exception: Record): string { const keys = Object.keys(convertToPlainObject(exception)); keys.sort(); - const firstKey = keys[0]; - - if (!firstKey) { - return '[object has no keys]'; - } - - if (firstKey.length >= maxLength) { - return truncate(firstKey, maxLength); - } - - for (let includedKeys = keys.length; includedKeys > 0; includedKeys--) { - const serialized = keys.slice(0, includedKeys).join(', '); - if (serialized.length > maxLength) { - continue; - } - if (includedKeys === keys.length) { - return serialized; - } - return truncate(serialized, maxLength); - } - - return ''; + return !keys[0] ? '[object has no keys]' : keys.join(', '); } /** diff --git a/packages/core/test/lib/utils/object.test.ts b/packages/core/test/lib/utils/object.test.ts index bc8c7611abb8..a4d2a4b56ea3 100644 --- a/packages/core/test/lib/utils/object.test.ts +++ b/packages/core/test/lib/utils/object.test.ts @@ -142,29 +142,26 @@ describe('fill()', () => { describe('extractExceptionKeysForMessage()', () => { test('no keys', () => { - expect(extractExceptionKeysForMessage({}, 10)).toEqual('[object has no keys]'); + expect(extractExceptionKeysForMessage({})).toEqual('[object has no keys]'); }); - test('one key should be returned as a whole if not over the length limit', () => { - expect(extractExceptionKeysForMessage({ foo: '_' }, 10)).toEqual('foo'); - expect(extractExceptionKeysForMessage({ foobarbazx: '_' }, 10)).toEqual('foobarbazx'); + test('one key should be returned as a whole', () => { + expect(extractExceptionKeysForMessage({ foo: '_' })).toEqual('foo'); + expect(extractExceptionKeysForMessage({ foobarbazx: '_' })).toEqual('foobarbazx'); }); - test('one key should be appended with ... and truncated when over the limit', () => { - expect(extractExceptionKeysForMessage({ foobarbazqux: '_' }, 10)).toEqual('foobarbazq...'); - }); - - test('multiple keys should be sorted and joined as a whole if not over the length limit', () => { - expect(extractExceptionKeysForMessage({ foo: '_', bar: '_' }, 10)).toEqual('bar, foo'); - }); - - test('multiple keys should include only as much keys as can fit into the limit', () => { - expect(extractExceptionKeysForMessage({ foo: '_', bar: '_', baz: '_' }, 10)).toEqual('bar, baz'); - expect(extractExceptionKeysForMessage({ footoolong: '_', verylongkey: '_', baz: '_' }, 10)).toEqual('baz'); - }); - - test('multiple keys should truncate first key if its too long', () => { - expect(extractExceptionKeysForMessage({ barbazquxfoo: '_', baz: '_', qux: '_' }, 10)).toEqual('barbazquxf...'); + test('multiple keys should be sorted and joined as a whole (without truncating)', () => { + const exception = { + property1: 'a', + thisIsAnExtremelyLongPropertyNameThatExceedsFortyCharacters: 'b', + barbazquxfooabc: 'x', + property3: 'c', + property4: 'd', + property5: 'e', + }; + expect(extractExceptionKeysForMessage(exception)).toEqual( + 'barbazquxfooabc, property1, property3, property4, property5, thisIsAnExtremelyLongPropertyNameThatExceedsFortyCharacters', + ); }); });