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

fix: some APIs modified for ASAR support cannot be util.promisify'ed #13845

Merged
merged 1 commit into from Aug 1, 2018

Conversation

miniak
Copy link
Contributor

@miniak miniak commented Jul 29, 2018

Fixes #13458

Promisification of the following functions is being fixed:

  • fs.exists()
  • child_process.exec()
  • child_process.execFile()
Checklist

@miniak miniak requested a review from a team July 29, 2018 12:33
@miniak miniak force-pushed the miniak/fix-promisify branch 5 times, most recently from 53fd254 to ac480ad Compare July 29, 2018 13:17
@miniak miniak changed the title [wip] fix: some APIs modified for ASAR support cannot be util.promisify'ed fix: some APIs modified for ASAR support cannot be util.promisify'ed Jul 29, 2018
Copy link
Member

@MarshallOfSound MarshallOfSound left a comment

Choose a reason for hiding this comment

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

.

@@ -27,6 +28,12 @@
return archive
}

function assertNoCustomPromisify (func) {
Copy link
Member

Choose a reason for hiding this comment

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

I feel as though these assertions should live inside tests, not runtime code 👍

Copy link
Member

Choose a reason for hiding this comment

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

Something along the lines of

for (const key in originalFs) {
  if (originalFs[key][util.promisify.custom] && !fs[key][util.promisify.custom]) {
    // fail the test
  }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@MarshallOfSound that's a really good point. I didn't notice the originalFs can be accessed in the tests. Done

}
const archive = getOrCreateArchive(asarPath)
if (!archive) {
return Promise.resolve(false)
Copy link
Member

Choose a reason for hiding this comment

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

This is inconsistent with the fs.exists behavior above, in the case of an invalid archive it throws / calls back with an error. This method will fail transparently with a resolved false

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@MarshallOfSound original fs.exists never throws, it always returns either true or false. I can make it reject in this case though.


const archive = getOrCreateArchive(asarPath)
if (!archive) {
return new Promise(() => invalidArchiveError(asarPath))
Copy link
Member

Choose a reason for hiding this comment

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

This should be return Promise.reject(invalidArchiveError(asarPath))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@MarshallOfSound that won't work, invalidArchiveError throws the error

Copy link
Member

Choose a reason for hiding this comment

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

Oh I see, this will result in a rejected promise right? 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes


const newPath = archive.copyFileOut(filePath)
if (!newPath) {
return new Promise(() => notFoundError(asarPath, filePath))
Copy link
Member

Choose a reason for hiding this comment

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

This should be return Promise.reject(notFoundError(asarPath, filePath))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@MarshallOfSound that won't work, notFoundError throws the error

@@ -644,6 +699,13 @@ describe('asar package', function () {
done()
})
})

it('can be promisified', (done) => {
util.promisify(ChildProcess.exec)('echo ' + echo + ' foo bar').then(({ stdout }) => {
Copy link
Member

Choose a reason for hiding this comment

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

This is a promise so we don't need to use the done technique. We can just return the promise in the test and the test will finish when the promise is resolved or rejected.

Copy link
Contributor Author

@miniak miniak Jul 30, 2018

Choose a reason for hiding this comment

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

var p = path.join(fixtures, 'asar', 'a.asar', 'file1')
// eslint-disable-next-line
fs.exists(p, function (exists) {
assert.equal(exists, true)
Copy link
Member

Choose a reason for hiding this comment

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

Can we use expect from the chair package instead of assert please, it will help the work that @codebytere is doing to improve our test suite

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@MarshallOfSound I don't want that to be back-ported to 2.0. It's small amount of code compared to the rest of the tests.

@miniak miniak force-pushed the miniak/fix-promisify branch 2 times, most recently from 93191f4 to c0afb79 Compare July 30, 2018 08:46
@MarshallOfSound MarshallOfSound merged commit c52b3d9 into master Aug 1, 2018
@MarshallOfSound MarshallOfSound deleted the miniak/fix-promisify branch August 1, 2018 03:06
@trop
Copy link
Contributor

trop bot commented Aug 1, 2018

An error occurred while attempting to backport this PR to "2-0-x", you will need to perform this backport manually

@trop
Copy link
Contributor

trop bot commented Aug 1, 2018

We have automatically backported this PR to "3-0-x", please check out #13902

@trop trop bot added merged/3-0-x and removed target/3-0-x labels Aug 1, 2018
@MarshallOfSound
Copy link
Member

@miniak

An error occurred while attempting to backport this PR to "2-0-x", you will need to perform this backport manually

☝️ if you want to get this into a 2.0.x release

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.

Behaviour of util.promisify(childProcess.exec) inconsistent with node
2 participants