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 1 commit into
base: develop
Choose a base branch
from

Conversation

ha1fstack
Copy link

@ha1fstack ha1fstack commented Aug 11, 2025

Before submitting a pull request, please take a look at our
Contributing guidelines and verify:

  • If you've added code that should be tested, please add tests.
  • Ensure your code lints and the test suite passes (yarn lint) & (yarn test).

closes #15142

When using ExtraErrorDataIntegration, error.cause serializes with .toString() which is not very informative considering the purpose of the integration.

This PR improves error.cause handling in ExtraErrorDataIntegration by recursing the _extractErrorData for a single cause depth. To match the outer structure and provide more information the cause object is wrapped with [name].

The .toString() serialized data is gone now but if we are using LinkedErrorsIntegration the string message will still be visible.

Since these changes are useful enough, I think more detailed specifications (like cause recursion) could be addressed by future PRs - open to suggestions.

Before:

// error.cause was serialized as: "SyntaxError: bar"
{
  TypeError: {
    cause: "SyntaxError: bar"  // Just toString() output
  }
}

After:

// error.cause now includes full error data extraction
{
  TypeError: {
    cause: {
      SyntaxError: {
        baz: 42,
        foo: "aaaa...a...",
      }
    }
  }
}

Copy link
Member

@s1gr1d s1gr1d left a comment

Choose a reason for hiding this comment

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

This sounds like a good idea. Thanks for submitting this

@@ -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 causeName = error.cause.name || error.cause.constructor.name;
Copy link
Member

Choose a reason for hiding this comment

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

Maybe change the variable name here to make it easier to understand that this is not the name of the cause but the error name as this is of type Error.

Or causeErrorName.

Suggested change
const causeName = error.cause.name || error.cause.constructor.name;
const errorName = error.cause.name || error.cause.constructor.name;

@s1gr1d s1gr1d requested a review from Lms24 August 11, 2025 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The ExtraErrorData integration is not capturing nested error causes
2 participants