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 于 238 天前认领,目前没有进行中的 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 小时 新手友好度 65/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
volcengine/OpenViking#8432 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 74/100
jupyterlab/eslint-plugin#178 · 2 条评论 ·
-
bug from-app needs-triage
难度 2/5 1-3 小时 新手友好度 65/100
nightly-labs/openbot#16303 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 72/100