datastore-s3 throws the wrong error when a file isn't found on s3

未关闭
#331 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
aws, typescript
领域
backend, cloud

调研方向

从 issue 中链接的 404 状态检查处开始查看 packages/datastore-s3/src/index.ts,并将其错误处理与 packages/datastore-fs/src/index.ts 进行比较。通过 helia.pins.add 或 helia.pins.ls 入口确认该行为;缺失的 S3 文件应产生 NotFoundError,而不是 GetFailedError。

由索引模型根据 Issue 内容生成。

描述

need/triage

When using datastore-s3, calling helia.pins.add or helia.pins.ls fails with a "NoSuchKey" error

err: {
      "type": "GetFailedError",
      "message": "NoSuchKey: The specified key does not exist.",

If a file isn't found a "NotFoundError" is gracefully handled, but a GetFailedError throws. datastore-s3's "get" method currently throws a GetFailedError when a given file isn't found.

This is because the 404 status check doesn't line up with the response from s3 (this line)

Applied the following patch to fix:

diff --git a/dist/src/index.js b/dist/src/index.js
index 3dc550c3fa0abaf3c6c1fe7bb7ca4107c824ba3d..88f43d0939f9dbc754097723c0bcab15fdacae88 100644
--- a/dist/src/index.js
+++ b/dist/src/index.js
@@ -113,7 +113,7 @@ export class S3Datastore extends BaseDatastore {
             return await toBuffer(data.Body);
         }
         catch (err) {
-            if (err.statusCode === 404) {
+            if (err.statusCode === 404 || err.$metadata.httpStatusCode === 404 || String(err).includes('NoSuchKey')) {
                 throw new NotFoundError(String(err));
             }
             throw new GetFailedError(String(err));

datastore-fs error handling for reference

主要语言
TypeScript
星标
39
派生
28
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

ipfs/js-stores 的其他 Issue

查看 ipfs/js-stores 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。