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

Aperta
#331 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
aws, typescript
Ambito
backend, cloud

Direzione di ricerca

Inizia in packages/datastore-s3/src/index.ts, in corrispondenza del controllo dello stato 404 collegato nell’issue, e confronta la gestione degli errori con quella di packages/datastore-fs/src/index.ts. Conferma il comportamento tramite i punti di ingresso helia.pins.add o helia.pins.ls; un file S3 mancante dovrebbe produrre NotFoundError invece di GetFailedError.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
TypeScript
Stelle
39
Fork
28
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ipfs/js-stores

Tutte le issue di ipfs/js-stores

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.