-
Notifications
You must be signed in to change notification settings - Fork 1.9k
vscode: added error handling to download file streams #3116
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
vscode: added error handling to download file streams #3116
Conversation
|
Will rebase this on top of #3115, since I forsee merge conflicts |
| `GitHub repository: ${err.message}` | ||
| ); | ||
|
|
||
| console.error(err); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not 100% sure we need to write the error out since the message is shown in vscode but I don't feel strongly about it. If you think it makes sense then that's fine by me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kjeremy err.message is as less verbose as it can, err.stack and console.error(err) are for the better debugging experience.
Here is the comparison:

| import { strict as assert } from "assert"; | ||
| import { NestedError } from "ts-nested-error"; | ||
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd remove the extra line of white space.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like a good idea to me! Left some nits. NOTE: I'm not terribly familiar with the TS.
|
@kjeremy, thank you for the review, I try to keep TS code as clean and easy to read as possible, so the nits are very welcome! |
759fe54 to
36dc3ed
Compare
|
Removed whitespace, left |
|
Waiting on the resolution of #3092 (comment). It seems like we should just use pipeline here. I think that gist is not necessary shows a problem: both the |
| ) | ||
| ); | ||
| await pipeline(res.body, destFileStream).catch(DownloadFileError.rethrow("Piping file error")); | ||
| return new Promise<void>(resolve => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need a Promise here at all? I would imagine that the following would work (with some exception safety added just in case):
try {
await pipeline(res.body, destFileStream);
return;
} finally {
destFileStream.destory()
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately it doesn't work on my laptop on windows ;( We still need to await the close event... Please see that discussion you originally referred to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, sorry, I've missed the last bit of the discussion :( Yeah, I guess the current code is what we should do then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By the way, regarding destroy() in finally, this is a bit convoluted...
The streams do get automatically disposed on "error" event. See documentation
stream.pipeline() will call stream.destroy(err) on all streams except:
Readable streams which have emitted 'end' or 'close'.
Writable streams which have emitted 'finish' or 'close'.
|
|
||
| const pipeline = util.promisify(stream.pipeline); | ||
|
|
||
| class DownloadFileError extends NestedError {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We never catch this specific error, so I don't think it makes much sense to do error wrapping at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just that the name of the error (i.e. the name of the class reflectively) is displayed in the error message. Though we can infer where the Errror came from by the nested callstacks, so this is not that important...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I would prefer to keep things simple by default, or rely on ubiquitous libraries (like rust's anynow) if there are big gains.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, will simplify!
|
@matklad, applied changes as per your comment |
| onProgress: (readBytes: number, totalBytes: number) => void | ||
| ): Promise<void> { | ||
| const res = await fetch(url); | ||
| const res = await fetch(url).catch(NestedError.rethrow("Failed at initial fetch")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still don't think that using non-ubiquitous helper libraries is a good tradeoff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, didn't understand you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will remove NestedError then...
4c63712 to
574dc11
Compare
|
bors r+ |
3116: vscode: added error handling to download file streams r=matklad a=Veetaha As a followup for #3092 `ts-nested-error` is mine, it is just [one file worth nothing](https://github.com/Veetaha/ts-nested-error/blob/master/src/nested-error.ts), but let's us inspect original errors Co-authored-by: Veetaha <gerzoh1@gmail.com>
Build succeeded
|
As a followup for #3092
ts-nested-erroris mine, it is just one file worth nothing, but let's us inspect original errors