Throw real Errors instead of objects
@psavan1655 已經在處理了。
開始於 2023年4月3日。
評估
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 新手友好度
- 35/100
- Issue 類型
- 缺陷
- 描述清晰度
- 基本清楚
- 活躍度
- 停滯
- 技術堆疊
- typescript
- 領域
- api
研究方向
從 packages/client-account/src/methods/accountCopyIndex.ts 和 packages/client-account/src/errors/createDestinationIndiceExistsError.ts 開始,接著檢查 issue 引用的其他錯誤輔助函式。決定一致的 Error 表示方式,並驗證拋出的失敗對 Sentry 等消費者保留其名稱、訊息和真實的堆疊追蹤。
由索引模型根據 Issue 內容生成。
描述
This package has a non standard behavior of throwing objects instead of real JS Errors. As it works approximately in the same way in most cases and these objects are similar to Error (at least, TS is ok with that), there are some edge cases where it messes everything up.
My specific use case is with Sentry, which is not able to handle properly these "errors". Instead of having a proper stack trace, I have the Sentry error Non-Error exception captured and all the informations about the real error are lost.
We do this kind of thing all over the package:
throw createDestinationIndiceExistsError()
createDestinationIndiceExistsError.ts
export function createDestinationIndiceExistsError(): Error {
return {
name: 'DestinationIndiceAlreadyExistsError',
message: 'Destination indice already exists.',
};
}
I propose instead to either throw a basic Error with the message...
export function createDestinationIndiceExistsError(): Error {
return new Error('DestinationIndiceAlreadyExistsError');
}
Or even to create custom error objects
class AlgoliaDestinationIndiceAlreadyExistsError extends Error {
constructor(message) {
super(message);
this.name = 'AlgoliaDestinationIndiceAlreadyExistsError';
}
}
export function createDestinationIndiceExistsError(): Error {
return new AlgoliaDestinationIndiceAlreadyExistsError('Destination indice already exists.');
}
I even think that this helper methods are not necessary and that custom errors could be thrown directly. For instance, the custom message is useless in this case.
I can open a PR with a proof of concept if you think it's a good idea. I would also be glad to hear your ideas about the right implementation.
- 主要語言
- TypeScript
- 星號
- 1.4k
- 分支
- 227
- PR 合併指標
- 30 天內沒有已合併 PR
環境準備
這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
algolia/algoliasearch-client-javascript 的其他 Issue
-
bug
難度 2/5 1-3 小時 新手友好度 62/100
algolia/algoliasearch-client-javascript#1583 · 14 則留言 · 9 個 reaction ·
-
難度 4/5 3-5 天 新手友好度 38/100
-
[bug]: Algolia JS Client cause `Bun` to crash on `Hono`可能重新可做 @PrevailUgah 於 239 天前認領,目前沒有進行中的 PR。 未關閉bug
難度 4/5 3-5 天 新手友好度 35/100
algolia/algoliasearch-client-javascript#1601 · 5 則留言 ·
-
難度 5/5 一週以上 新手友好度 25/100
-
bug
難度 3/5 1-2 天 新手友好度 45/100
algolia/algoliasearch-client-javascript#1594 · 4 則留言 ·
查看 algolia/algoliasearch-client-javascript 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 72/100
GetStream/stream-chat-react#3467 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 72/100
vercel-labs/ui#1139 ·
維護者通常 1 天內回覆
-
generate_image reference URL guard lets through IPv4-mapped IPv6 hosts and 100.64.0.0/10可能已有人在做 @goranai 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 75/100
維護者通常 1 天內回覆
-
bot:ai-assisted component:platform-js status:untriaged
難度 2/5 1-3 小時 新手友好度 82/100
midnightntwrk/platform-js#93 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 66/100