Skip to content
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

The ExtraErrorData integration is not capturing nested error causes #15142

Open
3 tasks done
michaelschufi opened this issue Jan 23, 2025 · 1 comment
Open
3 tasks done
Labels
Package: nextjs Issues related to the Sentry Nextjs SDK

Comments

@michaelschufi
Copy link

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

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Jan 23, 2025
@github-actions github-actions bot added the Package: nextjs Issues related to the Sentry Nextjs SDK label Jan 23, 2025
@andreiborza
Copy link
Member

Hi @michaelschufi, thanks for filing this.

I just tested this out and had a look at our code, indeed if cause is an Error or if a value of a property inside the JSON returned from toJSON is an Error it gets immediately serialized via toString regardless of having a toJSON itself.

This is something we can consider changing, I'll bring it up with the team. Otherwise, we also welcome contributions if you're interested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: nextjs Issues related to the Sentry Nextjs SDK
Projects
Status: No status
Development

No branches or pull requests

2 participants