From 1bc67538eb2a80ca7d4c1a1e6fc3be0c6d9be9a2 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Tue, 20 Dec 2022 17:50:16 +0530 Subject: [PATCH] add less than expected chunk count check --- src/services/upload/hashService.tsx | 2 +- src/utils/error/index.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/services/upload/hashService.tsx b/src/services/upload/hashService.tsx index ed5ba6c5a..e0a4766c0 100644 --- a/src/services/upload/hashService.tsx +++ b/src/services/upload/hashService.tsx @@ -23,7 +23,7 @@ export async function getFileHash(worker, file: File | ElectronFile) { for (let i = 0; i < filedata.chunkCount; i++) { const { done, value: chunk } = await streamReader.read(); if (done) { - break; + throw Error(CustomError.CHUNK_LESS_THAN_EXPECTED); } await worker.hashFileChunk(hashState, Uint8Array.from(chunk)); } diff --git a/src/utils/error/index.ts b/src/utils/error/index.ts index eac5bf652..7719d0f61 100644 --- a/src/utils/error/index.ts +++ b/src/utils/error/index.ts @@ -19,6 +19,7 @@ export enum CustomError { KEY_MISSING = 'encrypted key missing from localStorage', FAILED_TO_LOAD_WEB_WORKER = 'failed to load web worker', CHUNK_MORE_THAN_EXPECTED = 'chunks more than expected', + CHUNK_LESS_THAN_EXPECTED = 'chunks less than expected', UNSUPPORTED_FILE_FORMAT = 'unsupported file formats', FILE_TOO_LARGE = 'file too large', SUBSCRIPTION_EXPIRED = 'subscription expired',