Skip to content

How to override the error serializer? #17180

@punkpeye

Description

@punkpeye

Problem Statement

The problem is that I am throwing an error with custom properties, e.g.

export class UnexpectedStateError extends Error {
  public cause?: unknown;

  public extra?: Extras;

  public constructor(
    message: string,
    options?: { cause?: unknown; extra?: Extras },
  ) {
    super(message);

    this.name = new.target.name;
    this.extra = options?.extra;
    this.cause = options?.cause;
  }
}
throw new UnexpectedStateError('foo', {
  extra: {
    mcpServerId,
  },
});

Now, the earliest that I am able to catch the error appears to be here:

Sentry.addEventProcessor(async (event) => {
  console.log('[instrument] Sentry.addEventProcessor', event);

  return event;
});

but at this point, I already cannot find my extra property anymore.

Solution Brainstorm

  • allow to customize the serializer for erros
  • update the serializer to always capture the contents of extra property (aligns with captureException)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions