Open
Description
Is there an existing issue for this?
- I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
- I have reviewed the documentation https://docs.sentry.io/
- I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases
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
- Set up a custom error class that has a
toJSON
method, which includes thethis.cause
property. - 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.
Metadata
Metadata
Assignees
Type
Projects
Status
No status