Conversation
Result of running the await-promise-chain.js codemod from https://github.com/sgilroy/async-await-codemod
| grunt.log.writeln('Running click tests in parallel... (this will take a while...)'); | ||
| return Promise.all( | ||
| tests.map((file) => { | ||
| tests.map(async (file) => { |
There was a problem hiding this comment.
The whole clickParallel task still has a bunch of then. Why is only this part rewritten?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
As unhandledRejection doesn't seem to return anything, I would remove the return when it is called;
| return this.server.unhandledRejection(e); | |
| this.server.unhandledRejection(e); |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
Shouldn't this also be in a try/catch?
There was a problem hiding this comment.
Yes, looks like catches aren't always rewritten.
|
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. |
|
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? |
|
@Hirse we had this discussion some months ago over here #1178 (comment) I have currently a lot of work at work so I will probably reviewing PRs at the weekend. |
Oh, right. 😄 I still think we should mention the supported browsers (in the Readme). |
campersau
left a comment
There was a problem hiding this comment.
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.
| grunt.log.writeln('Running click tests in parallel... (this will take a while...)'); | ||
| return Promise.all( | ||
| tests.map((file) => { | ||
| tests.map(async (file) => { |
There was a problem hiding this comment.
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) { | |||
There was a problem hiding this comment.
For example let's change that here.
|
|
||
| return programEvents.dispatch({ event: 'working-tree-changed' }); | ||
| } catch (e) { | ||
| return this.server.unhandledRejection(e); |
There was a problem hiding this comment.
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', { |
There was a problem hiding this comment.
This is actually wrong, because postPromise does return a promise which isn't awaited and try catched here!
| name: this.refName, | ||
| }); | ||
| if (isRemote && isLocalCurrent) { | ||
| return this.server.postPromise('/reset', { |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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) => { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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' }) |
There was a problem hiding this comment.
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'); |
|
I'll wait to revisit this until #1461 is merged, since it will cause a bunch of conflicts |
The result of running the async-await codemod and some fixes