Skip to content

feat(core): better cause data extraction #17375

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
wants to merge 2 commits into
base: develop
Choose a base branch
from
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
7 changes: 6 additions & 1 deletion packages/core/src/integrations/extraerrordata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,12 @@ function _extractErrorData(
// Error.cause is a standard property that is non enumerable, we therefore need to access it separately.
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause
if (captureErrorCause && error.cause !== undefined) {
extraErrorInfo.cause = isError(error.cause) ? error.cause.toString() : error.cause;
if (isError(error.cause)) {
const errorName = error.cause.name || error.cause.constructor.name;
extraErrorInfo.cause = { [errorName]: _extractErrorData(error.cause as ExtendedError, false, maxValueLength) };
} else {
extraErrorInfo.cause = error.cause;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Error Handling Regression

When _extractErrorData (called for error.cause) returns null due to an extraction failure, extraErrorInfo.cause is incorrectly set to { [errorName]: null }. This is a regression from the previous behavior, which fell back to error.cause.toString(), providing a more consistent and useful representation when detailed extraction fails.

Fix in Cursor Fix in Web

}

// Check if someone attached `toJSON` method to grab even more properties (eg. axios is doing that)
Expand Down
13 changes: 10 additions & 3 deletions packages/core/test/lib/integrations/extraerrordata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ describe('ExtraErrorData()', () => {
});
});

it('doesnt choke on linked errors and stringify names instead', () => {
it('should extract error data from the error cause with the same policy', () => {
const error = new TypeError('foo') as ExtendedError;
error.cause = new SyntaxError('bar');
error.cause = new SyntaxError('bar') as ExtendedError;
error.cause.baz = 42;
error.cause.foo = 'a'.repeat(300);

const enhancedEvent = extraErrorData.processEvent?.(
event,
Expand All @@ -69,7 +71,12 @@ describe('ExtraErrorData()', () => {

expect(enhancedEvent.contexts).toEqual({
TypeError: {
cause: 'SyntaxError: bar',
cause: {
SyntaxError: {
baz: 42,
foo: `${'a'.repeat(250)}...`,
},
},
},
});
});
Expand Down