Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(core): Include all exception object keys instead of truncating #18044

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
s1gr1d wants to merge 3 commits into develop
base: develop
Choose a base branch
Loading
from sig/noErrorMaxLength
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 2 additions & 24 deletions packages/core/src/utils/object.ts
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<string, unknown>, maxLength: number = 40): string {
export function extractExceptionKeysForMessage(exception: Record<string, unknown>): 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(', ');
}

/**
Expand Down
35 changes: 16 additions & 19 deletions packages/core/test/lib/utils/object.test.ts
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -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',
);
});
});

Expand Down
Loading

AltStyle によって変換されたページ (->オリジナル) /