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

Open
#331 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
35/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
aws, typescript
Domain
backend, cloud

Research direction

Start in packages/datastore-s3/src/index.ts at the 404 status check linked in the issue, and compare its error handling with packages/datastore-fs/src/index.ts. Confirm the behavior through the helia.pins.add or helia.pins.ls entry points; a missing S3 file should produce NotFoundError rather than GetFailedError.

Written by the indexing model from the issue text.

Description

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

Dominant language
TypeScript
Stars
39
Forks
28
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ipfs/js-stores

All issues in ipfs/js-stores

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.