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

Handle SuppressedError #8441

Open
timfish opened this issue Jul 1, 2023 · 1 comment
Open

Handle SuppressedError #8441

timfish opened this issue Jul 1, 2023 · 1 comment
Labels
Package: core Issues related to the Sentry Core SDK Type: Improvement

Comments

@timfish
Copy link
Collaborator

timfish commented Jul 1, 2023

Problem Statement

Explicit Resource Management has reached TC39 stage 3:
https://github.com/tc39/proposal-explicit-resource-management

Support has been added to TypeScript 5.2 beta:
https://devblogs.microsoft.com/typescript/announcing-typescript-5-2-beta/#using-declarations-and-explicit-resource-management

When this makes it into browsers/node.js/platforms, there will be a new error type called SuppressedError which wraps any exception thrown and also any exception thrown during resource disposal.

Reporting SuppressedError directly to Sentry will likely be not that useful so the error(s) should be pulled out.

class SuppressedError extends Error {
  /**
   * Wraps an error that suppresses another error, and the error that was suppressed.
   * @param {*} error The error that resulted in a suppression.
   * @param {*} suppressed The error that was suppressed.
   * @param {string} message The message for the error.
   * @param {{ cause?: * }} [options] Options for the error.
   */
  constructor(error, suppressed, message, options);

  /**
   * The name of the error (i.e., `"SuppressedError"`).
   * @type {string}
   */
  name = "SuppressedError";

  /**
   * The error that resulted in a suppression.
   * @type {*}
   */
  error;

  /**
   * The error that was suppressed.
   * @type {*}
   */
  suppressed;

  /**
   * The message for the error.
   * @type {*}
   */
  message;
}

The TypeScript introduction gives a good example of how these properties are populated:

class ErrorA extends Error {
    name = "ErrorA";
}
class ErrorB extends Error {
    name = "ErrorB";
}

function throwy(id: string) {
    return {
        [Symbol.dispose]() {
            throw new ErrorA(`Error from ${id}`);
        }
    };
}

function func() {
    using a = throwy("a");
    throw new ErrorB("oops!")
}

try {
    func();
}
catch (e: any) {
    console.log(e.name); // SuppressedError
    console.log(e.message); // An error was suppressed during disposal.

    console.log(e.error.name); // ErrorA
    console.log(e.error.message); // Error from a

    console.log(e.suppressed.name); // ErrorB
    console.log(e.suppressed.message); // oops!
}
@timfish
Copy link
Collaborator Author

timfish commented Jul 2, 2023

Related to Handle AggregateErrors

@timfish timfish changed the title Add support for pulling error from SuppressedError Handle SuppressedError Jul 2, 2023
@AbhiPrasad AbhiPrasad added the Package: core Issues related to the Sentry Core SDK label Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: core Issues related to the Sentry Core SDK Type: Improvement
Projects
Status: Waiting for: Product Owner
Development

No branches or pull requests

5 participants