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

Async await #1358

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Async await #1358

wants to merge 7 commits into from

Conversation

wmertens
Copy link
Contributor

The result of running the async-await codemod and some fixes

@@ -332,32 +331,33 @@ module.exports = (grunt) => {
.then((tests) => {
grunt.log.writeln('Running click tests in parallel... (this will take a while...)');
return Promise.all(
tests.map((file) => {
tests.map(async (file) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

The whole clickParallel task still has a bunch of then. Why is only this part rewritten?

Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like promises which are not returned in a function are not going to be rewritten because that would change the return type to be a Promise instead of void.
This is fine in some places like here but we might want do change that in other places.


return programEvents.dispatch({ event: 'working-tree-changed' });
} catch (e) {
return this.server.unhandledRejection(e);
Copy link
Contributor

@Hirse Hirse May 11, 2020

Choose a reason for hiding this comment

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

As unhandledRejection doesn't seem to return anything, I would remove the return when it is called;

Suggested change
return this.server.unhandledRejection(e);
this.server.unhandledRejection(e);

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, it does not return anyting, the rewrite is just using the same returns as before.
So before

.catch((e) => this.server.unhandledRejection(e));

did also return undefined.
But I agree we should change that!

.postPromise('/createDir', { dir: this.repoPath() })
.catch((e) => this.server.unhandledRejection(e))
.then(() => this.updateStatus());
.catch((e) => this.server.unhandledRejection(e));
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this also be in a try/catch?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, looks like catches aren't always rewritten.

@Hirse
Copy link
Contributor

Hirse commented May 11, 2020

I started to review a bit, but the diff is so large that it is difficult to check everything.

In general, the codemod seems good, but it doesn't seem to remove all promises.
I'm a bit confused when .then is converted to await and when it isn't.

@Hirse
Copy link
Contributor

Hirse commented May 11, 2020

Also, by changing the UI code to use async/await, we are dropping support for all IE versions.

@campersau, @jung-kim, which browsers are currently supported or supposed to be supported?

@campersau
Copy link
Collaborator

@Hirse we had this discussion some months ago over here #1178 (comment)
And as you can see we have dropped IE support a long time ago 😃
I addition to that I removed Bluebird which means browsers also have to support promises and even Promise.prototype.finally which was added later than async / await!


I have currently a lot of work at work so I will probably reviewing PRs at the weekend.

@Hirse
Copy link
Contributor

Hirse commented May 14, 2020

@Hirse we had this discussion some months ago over here #1178 (comment)

Oh, right. 😄
Thanks for the reminder.

I still think we should mention the supported browsers (in the Readme).

Copy link
Collaborator

@campersau campersau left a comment

Choose a reason for hiding this comment

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

I reviewed the hole thing made a few changes and fixed a few bugs over here
wmertens/ungit@async-await...campersau:async-await
This also makes the tests pass again.

Maybe splitting the PR into smaller pieces might help reviewing it, e.g. frontend code, backend code, tests.

@@ -332,32 +331,33 @@ module.exports = (grunt) => {
.then((tests) => {
grunt.log.writeln('Running click tests in parallel... (this will take a while...)');
return Promise.all(
tests.map((file) => {
tests.map(async (file) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like promises which are not returned in a function are not going to be rewritten because that would change the return type to be a Promise instead of void.
This is fine in some places like here but we might want do change that in other places.

@@ -133,11 +133,10 @@ class AppViewModel {
);
}
gitSetUserConfig(bugTracking) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

For example let's change that here.


return programEvents.dispatch({ event: 'working-tree-changed' });
} catch (e) {
return this.server.unhandledRejection(e);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, it does not return anyting, the rewrite is just using the same returns as before.
So before

.catch((e) => this.server.unhandledRejection(e));

did also return undefined.
But I agree we should change that!

if (err.errorCode != 'merge-failed') this.server.unhandledRejection(err);
try {
if (isRemote && !isLocalCurrent) {
return this.server.postPromise('/branches', {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is actually wrong, because postPromise does return a promise which isn't awaited and try catched here!

});
if (isRemote && isLocalCurrent) {
return this.server.postPromise('/reset', {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is actually wrong, because postPromise does return a promise which isn't awaited and try catched here!

const ammendFlag = amend ? '--amend' : '';
const allowedEmptyFlag = emptyCommit || amend ? '--allow-empty' : '';
const isGPGSign = config.isForceGPGSign ? '-S' : '';
return git(
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is actually wrong, because git does return a promise which isn't awaited and try catched here!

// bare repositories don't support `--show-toplevel` since git 2.25
return { type: 'bare', gitRootPath: repoPath };
}
return git(['rev-parse', '--show-toplevel'], repoPath).then((topLevel) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is actually wrong, because git does return a promise which isn't awaited and try catched here!

try {
await fs.access(config.pluginDirectory);

return loadPlugins(plugins, config.pluginDirectory);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is actually wrong, because loadPlugins does return a promise which isn't awaited and try catched here!
Also returning here is wrong because this function should return the plugins instead.

await fs.access(userConfigPath);

return fs
.readFile(userConfigPath, { encoding: 'utf8' })
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is actually wrong, because readFile does return a promise which isn't awaited and try catched here!

await common.put(req, '/gitignore', { path: testDir, data: 'abc' });

const res2 = await common.get(req, '/gitignore', { path: testDir });
await expect(res2.content).to.be('abc');
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is wrong!

@wmertens
Copy link
Contributor Author

wmertens commented Feb 1, 2021

I'll wait to revisit this until #1461 is merged, since it will cause a bunch of conflicts

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.

None yet

3 participants