getsentry / getsentry/sentry-javascript

Handle `SuppressedError`

未關閉
#8,441 1 則留言 1 個 reaction 已指派 0 人 在 GitHub 檢視
Core Improvement
主要語言
TypeScript
星號
8.7k
分支
1.8k
平均合併
1 天 18 小時
30 天內合併 PR
541

描述

### 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`](https://github.com/tc39/proposal-explicit-resource-management#the-suppressederror-error) 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.

```ts
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:
```ts
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!
}
```

貢獻指南

開啟貢獻指南

研究方向

先閱讀 TC39 Explicit Resource Management 提案以及 issue 中連結的 TypeScript 5.2 範例。定義應如何擷取巢狀的 `error` 和 `suppressed` 值以供報告使用,然後新增涵蓋範圍,顯示兩個底層錯誤都會被回報,而不只是 `SuppressedError` 包裝器。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
javascript, typescript
領域
observability
Issue 類型
功能
難度
4/5
預估耗時
3-5 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。