Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Npm: download the required binaries during installation #188

Merged
merged 17 commits into from
Jun 2, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
When download failed, throw message with details of what exactly failed
  • Loading branch information
Envek committed May 20, 2021
commit c7b3bbb78a1498728d7348f44c2c6249e15f7df5
10 changes: 4 additions & 6 deletions .npm/postinstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,11 @@ async function downloadBinary() {
fileName,
retry: { maxRetries: 5, delay: 50 },
})
dl.on("end", () => console.log("lefthook binary was downloaded"))
try {
await dl.start()
} catch(e) {
console.error(`Failed to download ${fileName} while fetching ${downloadURL}`)
dl.on("error", (e) => {
e.message = `Failed to download ${fileName}: ${e.message} while fetching ${downloadURL}`
throw e
Copy link
Contributor Author

@aminya aminya May 20, 2021

Choose a reason for hiding this comment

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

Does throwing the error here prevent retrying? What I had here allowed the code to retry downloading only throw the error in the end.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, this is good question.

Copy link
Member

Choose a reason for hiding this comment

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

Looks like it actually prevent retrying. But I believe it is a bug.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we should revert this change. What I had here allowed retrying, and also printed the actual error message.

Copy link
Member

Choose a reason for hiding this comment

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

Well, the problem is that printing doesn't work (at least with yarn). I will experiment with error throwing again later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You could replace this throw e with console.error(e), and then revert what I had to throw the last error.

Suggested change
throw e
console.error(e)

Copy link
Member

Choose a reason for hiding this comment

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

console.error output isn't visible when yarn is used to install package.

Copy link
Contributor Author

@aminya aminya May 24, 2021

Choose a reason for hiding this comment

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

Then there is no way to print the intermediate error messages with Yarn. I recommend throwing the last error for those on Yarn and let the algorithm work normally for others. This is not a bug in node-downloader-helper. The error callback expects a working code, and if we again rethrow the error in the error callback, we are doing redundant work.

Copy link
Member

Choose a reason for hiding this comment

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

Reverted my commit

I couldn't make yarn to print error message in a descriptive way I want because yarn is exiting on the first error event thrown (and I insist that this is caused by the bug in node-download helper, see hgouveia/node-downloader-helper#57 (comment)).

I give up. Let it be so.

}
})
await dl.start()
return path.join(binDir, fileName)
}

Expand Down