Skip to content

Commit

Permalink
error handling for stream
Browse files Browse the repository at this point in the history
  • Loading branch information
Aiqiao Yan authored and Aiqiao Yan committed May 11, 2020
1 parent da9f90c commit ee7a57c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
6 changes: 5 additions & 1 deletion dist/restore/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
})));
Expand Down
6 changes: 5 additions & 1 deletion dist/save/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
})));
Expand Down
18 changes: 12 additions & 6 deletions src/cacheHttpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down

0 comments on commit ee7a57c

Please sign in to comment.