Skip to content

Conversation

@ericsciple
Copy link
Contributor

@ericsciple ericsciple commented Mar 4, 2020

Update tool-cache downloadTool() to handle errors from response body stream

related to actions/setup-node#116

import * as core from '@actions/core'

/**
* Internal class for retries
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Private for now. If expose a class for consumers we probably want to put more thought into the interface and behaviors. And probably do exponent backoff in that case.

() => response.message
)
const readStream = responseMessageFactory()
readStream.pipe(file)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts on using pipeline? It can be promisified, and deals with errors from all streams

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will look into switching over to that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is waaaaay better

thanks!

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great! 👍

if (!succeeded) {
core.debug('download failed')
try {
await io.rmRF(dest)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we can't delete the dest on error, then the next retry will just error with Destination file path ${dest} already exists.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it shouldnt happen. If so then a bug we need to figure out.

const readStream = responseMessageFactory()
let succeeded = false
try {
await pipeline(readStream, fs.createWriteStream(dest))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A module method to pipe between streams and generators forwarding errors and properly cleaning up and provide a callback when the pipeline is complete.

Copy link
Collaborator

@thboop thboop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ericsciple ericsciple force-pushed the users/ericsciple/m167download branch from aeb718e to 7d54cbf Compare March 5, 2020 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants