Repository navigation
Handle SuppressedError #8441
Copy link
Copy link
Open
Labels
Description
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!
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsWaiting for: Product Owner
- StatusShow more project fieldsNo status
Activity
timfish commentedon Jul 2, 2023
[-]Add support for pulling error from `SuppressedError`[/-][+]Handle `SuppressedError`[/+]kunal649 commentedon Oct 11, 2026
I opened a draft for this: #25246.
So, I tried it on the Node SDK first. A SuppressedError only shows up as the wrapper ("An error was suppressed during disposal"), and
causeis empty, so LinkedErrors has nothing to follow. The two real errors are on.errorand.suppressed, so the PR reads those, like it does forcauseanderrors[].It's my first PR in this repo, so please tell me if you'd do something differently. I'm not suree about the
is_exception_groupflag on the wrapper, i explained it in the PR.JPeer264 commentedon Oct 12, 2026
hey @kunal649 thanks for opening up the PR. We'll have a look on your PR