-
-
Notifications
You must be signed in to change notification settings - Fork 55
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
Error event is emitted before every try even if download finished successfully #57
Comments
Hey, as far as I understand it the this.dl.start().catch(err => {
this.status = `failed`;
this.emit(`failed`, err);
return;
}); Hope this helps :) |
No,
So, if I run following code in const { DownloaderHelper } = require("node-downloader-helper");
(async () => {
const dl = new DownloaderHelper(
"https://nonexist.example.com",
".",
{ fileName: "anything", retry: { maxRetries: 3, delay: 50 } },
);
dl.on("retry", console.debug);
dl.on("end", console.info);
try {
await dl.start()
} catch (e) {
throw new Error(`I GIVE UP! ${e.message}`)
}
})() Expected result: 3 retries are performed, custom error is thrown:
Actual result: No retries performed, original error is thrown:
Workaround: Always add some dummy error handler: dl.on("error", () => {}); |
Hello @Envek , i just added a fix for this, i wonder if you could try it by install it like this |
Now it performs 3 retries as expected, but then it emits Now it works almost as expected, thank you! Here is runnable example and its outputYou can paste it right into bash or zsh shell: xargs -0 <<'JS' node --eval
const { DownloaderHelper } = require("node-downloader-helper");
(async () => {
const dl = new DownloaderHelper(
"https://nonexist.example.com",
".",
{ fileName: "anything", retry: { maxRetries: 3, delay: 50 } },
)
dl.on("retry", (...args) => console.debug("RETRY: ", ...args))
dl.on("end", (...args) => console.info("COMPLETED: ", ...args))
dl.on('error', (e) => console.error("ERROR EMITTED: ", e))
try {
await dl.start()
} catch (e) {
console.error(`I GIVE UP\! ${e.message}`)
}
})()
JS Output:
|
Seems to happen because of this change My guess is the |
Hello @Envek i just did a new fix, could you try once again? |
@hgouveia, now it emits error event only once. Thank you! Output of the same runnable example on fresh dev branch
|
commit 33aab44 Author: Jose De Gouveia <dhgouveia@gmail.com> Date: Mon Oct 4 11:12:26 2021 +0200 Incremented 1.0.19 commit ac8387f Author: Jose De Gouveia <dhgouveia@gmail.com> Date: Tue Aug 24 17:43:35 2021 +0200 Fixed attempt to ECONNRESET at TLSWrap.onStreamRead #61 commit 305676e Author: Jose De Gouveia <dhgouveia@gmail.com> Date: Tue Aug 24 14:42:20 2021 +0200 Fixed raise error event when paused in newer nodejs versions #62 commit 9d1bd9c Author: Jose De Gouveia <dhgouveia@gmail.com> Date: Fri Aug 20 16:44:12 2021 +0200 Fixed muiltiple 'error' emits when retry #57 commit e8c00d8 Author: Jose De Gouveia <dhgouveia@gmail.com> Date: Thu Aug 19 16:44:57 2021 +0200 Fixed error emitting when retry #57 commit bc20b86 Author: Jose De Gouveia <dhgouveia@gmail.com> Date: Thu Aug 19 14:51:48 2021 +0200 When timeout, it will retry the download if available if not emit timeout #40 commit 1306bc8 Author: Henrique Bruno Fantauzzi de Almeida <henrique.bruno.fa@gmail.com> Date: Tue Aug 17 04:42:25 2021 -0300 fileName {ext} type now also optional and boolean (#51) This fixes the typing for fileName property, now accepting: `fileName: {name: 'xyz'}` `fileName: {name: 'xyz', ext: true}` or false, stating false is the default `fileName: {name: 'xyz', ext: 'jpg'}` as already was accepted commit bed68d5 Author: Chaphasilor <ppp.u@web.de> Date: Tue Aug 17 09:41:05 2021 +0200 Fix leading dots being removed (#59) * fix leading dots being removed * only modify auto-generated filenames + added test
@Envek published to npm v1.0.19 |
Hey, thank you for this package, it helps.
However, I found some confusing behavior that I believe is a bug.
error
event is emitted after every unsuccessful try even if download was successful.In my understanding of EventEmitter errors,
error
event is (usually) a fatal one: it can't be recovered and you need to restart everything from scratch.For example:
Suppose that network error occurs for first two times, but on third try file downloads successfully.
Expected behavior:
error
event isn't fired if download was successful after all.Actual behavior:
error
event is emitted before every try.The text was updated successfully, but these errors were encountered: