Skip to content

Commit

Permalink
Merge pull request #300 from actions/aiyan/listen-on-error
Browse files Browse the repository at this point in the history
error handling for stream
  • Loading branch information
Aiqiao Yan authored and GitHub committed May 11, 2020
2 parents 5ddc028 + 4967c8e commit 916cc60
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 @@ -2379,11 +2379,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 @@ -2379,11 +2379,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 @@ -295,12 +295,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 916cc60

Please sign in to comment.