Skip to content

The ExtraErrorData integration is not capturing nested error causes #15142

@michaelschufi

Description

@michaelschufi

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/nextjs

SDK Version

8.51.0

Framework Version

Next 15.1.3

Link to Sentry event

https://sally-and-friends.sentry.io/issues/6215894150/events/2b86efb54ff54674bac3bd0582bc1952/

Reproduction Example/SDK Setup

// sentry.server.config (same for the other two)

Sentry.init({
  integrations: [
    Sentry.extraErrorDataIntegration({
      depth: 15,
    }),
  ],
  normalizeDepth: 15,
});

// my custom error class' toJSON

export class CustomError extends Error {
  // ... tell me if you need the whole class. But the point is, that this.cause is returned inside `toJSON`

  toJSON(): Record<string, unknown> {
    return {
      message: this.message,
      name: this.name,
      cause: this.cause,
    };
  }
}

Steps to Reproduce

  1. Set up a custom error class that has a toJSON method, which includes the this.cause property.
  2. Throw an error which has such error in its cause. E.g.
    throw new TRPCError("Top-level error", {
      cause: new CustomError("Nested error", {
        foo: "bar"
      })
    })

Expected Result

The top-level error is getting serialized, including the extra error data.
The cause field is another structured error data. E.g.

{
  message: "Nested error",
  name: "Custom Error",
  cause: {foo: "bar"},
}

because capturing the cause is enabled by default.

Actual Result

The nested error getting serialized in the format `${errorClassName}: ${message} instead of the whole structured data.

Image

Metadata

Metadata

Assignees

No one assigned
    No fields configured for issues without a type.

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions