From ee7a57c6158120f107592e03bf5b612fc582ff88 Mon Sep 17 00:00:00 2001 From: Aiqiao Yan Date: Fri, 8 May 2020 14:27:52 -0400 Subject: [PATCH] error handling for stream --- dist/restore/index.js | 6 +++++- dist/save/index.js | 6 +++++- src/cacheHttpClient.ts | 18 ++++++++++++------ 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/dist/restore/index.js b/dist/restore/index.js index d2b9af7..6d88c89 100644 --- a/dist/restore/index.js +++ b/dist/restore/index.js @@ -1435,11 +1435,15 @@ function uploadFile(httpClient, cacheId, archivePath) { const start = offset; const end = offset + chunkSize - 1; offset += MAX_CHUNK_SIZE; - yield uploadChunk(httpClient, resourceUrl, () => fs.createReadStream(archivePath, { + yield uploadChunk(httpClient, resourceUrl, () => fs + .createReadStream(archivePath, { fd, start, end, autoClose: false + }) + .on("error", error => { + throw new Error(`Cache upload failed because file read failed with ${error.Message}`); }), start, end); } }))); diff --git a/dist/save/index.js b/dist/save/index.js index acb0391..e91ab93 100644 --- a/dist/save/index.js +++ b/dist/save/index.js @@ -1434,11 +1434,15 @@ function uploadFile(httpClient, cacheId, archivePath) { const start = offset; const end = offset + chunkSize - 1; offset += MAX_CHUNK_SIZE; - yield uploadChunk(httpClient, resourceUrl, () => fs.createReadStream(archivePath, { + yield uploadChunk(httpClient, resourceUrl, () => fs + .createReadStream(archivePath, { fd, start, end, autoClose: false + }) + .on("error", error => { + throw new Error(`Cache upload failed because file read failed with ${error.Message}`); }), start, end); } }))); diff --git a/src/cacheHttpClient.ts b/src/cacheHttpClient.ts index 1b34a58..cecdaae 100644 --- a/src/cacheHttpClient.ts +++ b/src/cacheHttpClient.ts @@ -268,12 +268,18 @@ async function uploadFile( httpClient, resourceUrl, () => - fs.createReadStream(archivePath, { - fd, - start, - end, - autoClose: false - }), + fs + .createReadStream(archivePath, { + fd, + start, + end, + autoClose: false + }) + .on("error", error => { + throw new Error( + `Cache upload failed because file read failed with ${error.Message}` + ); + }), start, end );