Skip to content

Conversation

@Veetaha
Copy link
Contributor

@Veetaha Veetaha commented Feb 11, 2020

As a followup for #3092
ts-nested-error is mine, it is just one file worth nothing, but let's us inspect original errors

@Veetaha Veetaha requested review from kjeremy and matklad February 11, 2020 21:33
@Veetaha
Copy link
Contributor Author

Veetaha commented Feb 11, 2020

Will rebase this on top of #3115, since I forsee merge conflicts

`GitHub repository: ${err.message}`
);

console.error(err);
Copy link
Contributor

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.

Copy link
Contributor Author

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:
image

import { strict as assert } from "assert";
import { NestedError } from "ts-nested-error";


Copy link
Contributor

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.

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 do!

Copy link
Contributor

@kjeremy kjeremy left a 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.

@Veetaha
Copy link
Contributor Author

Veetaha commented Feb 11, 2020

@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!

@Veetaha Veetaha force-pushed the feature/add-error-handling-to-download-file-streams branch from 759fe54 to 36dc3ed Compare February 11, 2020 21:59
@Veetaha
Copy link
Contributor Author

Veetaha commented Feb 11, 2020

Removed whitespace, left console.error(), rebased the branch due to merge conflicts as mentioned in PR description.
Moved on(event, callback) calls for write-stream outside of pipe() call, since it returns the write-stream itself

@matklad
Copy link
Contributor

matklad commented Feb 12, 2020

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 on('close') callback and the await pipeline should be run after close event, and I don't think there's any specifc ordering on them? Ie, i would imagine the on('close') thing might schedule a closure with SetTimeout(closure, 0), just to make sure it is not run on the stack which did the actual closing of the file .

)
);
await pipeline(res.body, destFileStream).catch(DownloadFileError.rethrow("Piping file error"));
return new Promise<void>(resolve => {
Copy link
Contributor

@matklad matklad Feb 13, 2020

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()
}

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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 {}
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, will simplify!

@Veetaha
Copy link
Contributor Author

Veetaha commented Feb 13, 2020

@matklad, applied changes as per your comment

@Veetaha Veetaha requested a review from matklad February 13, 2020 20:22
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"));
Copy link
Contributor

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.

Copy link
Contributor Author

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

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 remove NestedError then...

@Veetaha Veetaha force-pushed the feature/add-error-handling-to-download-file-streams branch from 4c63712 to 574dc11 Compare February 13, 2020 22:33
@Veetaha Veetaha requested a review from matklad February 13, 2020 22:34
@matklad
Copy link
Contributor

matklad commented Feb 13, 2020

bors r+

bors bot added a commit that referenced this pull request Feb 13, 2020
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>
@bors
Copy link
Contributor

bors bot commented Feb 13, 2020

Build succeeded

  • Rust (macos-latest)
  • Rust (ubuntu-latest)
  • Rust (windows-latest)
  • TypeScript

@bors bors bot merged commit 574dc11 into rust-lang:master Feb 13, 2020
@Veetaha Veetaha deleted the feature/add-error-handling-to-download-file-streams branch February 24, 2020 20:10
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.

3 participants