Skip to content

handle response body error - #369

Merged
ericsciple merged 1 commit into
masterfrom
users/ericsciple/m167download
Mar 5, 2020
Merged

ericsciple merged 1 commit into
masterfrom
users/ericsciple/m167download

Conversation

@ericsciple

@ericsciple ericsciple commented Mar 4, 2020 •

Copy link
Copy Markdown
Contributor

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

related to actions/setup-node#116

Comment thread packages/tool-cache/src/tool-cache.ts Resolved
Comment thread packages/tool-cache/src/tool-cache.ts Resolved
Comment thread packages/tool-cache/src/tool-cache.ts Resolved
Comment thread packages/tool-cache/src/tool-cache.ts Resolved
Comment thread packages/tool-cache/src/tool-cache.ts Resolved
Comment thread packages/tool-cache/src/tool-cache.ts Resolved
Comment thread packages/tool-cache/src/tool-cache.ts Resolved
import * as core from '@actions/core'

/**
* Internal class for retries

Copy link
Copy Markdown
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.

Comment thread packages/tool-cache/package.json Resolved
Comment thread packages/tool-cache/src/tool-cache.ts Outdated
() => response.message
)
const readStream = responseMessageFactory()
readStream.pipe(file)

Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

@thboop thboop left a comment

Copy link
Copy Markdown
Collaborator

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.

4 participants