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

refactor(installer): return more-helpful error message on fakeroot ENOENT #55

Merged

Conversation

anulman
Copy link
Contributor

@anulman anulman commented Feb 23, 2017

Hi @unindented!

Was adding multi-platform installer support to electron-forge with @malept (i.e. "create a debian installer from a mac / darwin machine"), who recommended we provide more helpful error messages if the installer generation fails; this PR is a spike for that work.

This PR is kind of kludge-y, and isn't helpful when e.g. dpkg is not available on the host system. Ideally, a bit more work / thought would happen prior to merge, particularly around the downstream API for errors emitted to the provided callback.

Is this something you've been thinking about / had requests for? If not, is it something you're open to discussing?

src/installer.js Outdated
@@ -44,6 +44,14 @@ var spawn = function (options, command, args, callback) {
})

spawnedProcess.on('error', function (err) {
if (err.name = 'ENOENT') {
var installer = process.platform === 'darwin' ? 'brew' : 'apt-get'
Copy link
Member

Choose a reason for hiding this comment

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

Heh, this is not accurate on a non-Debian-derived Linux distro 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I know 😢

@malept / @unindented any canonical sources you'd recommend for this, or would it be better to prepend an "e.g."?

Copy link
Member

Choose a reason for hiding this comment

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

Better to prepend an "e.g.", waaaay too many Linux package managers out there.

src/installer.js Outdated
@@ -44,6 +44,14 @@ var spawn = function (options, command, args, callback) {
})

spawnedProcess.on('error', function (err) {
if (err.name = 'ENOENT') {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be err.name === 'ENOENT' 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.

😖

src/installer.js Outdated
var installer = process.platform === 'darwin' ? 'brew' : 'apt-get'

if (err.message.indexOf('fakeroot') > -1) {
err.message = 'Your system is missing the fakeroot package. Try ' + installer + ' install fakeroot'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe put the command in quotes, like:

err.message = 'Your system is missing the fakeroot package. Try `' + installer + ' install fakeroot`'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 , had it like that originally but changed syntax to better match the file's style

@unindented
Copy link
Collaborator

Better error messages are always a good thing!

@anulman
Copy link
Contributor Author

anulman commented Feb 24, 2017

Fantastic, thanks @unindented & @malept for the response + comments.

@unindented—the error messages end up being pretty verbose given the construction of how the error is constructed for the callback below. I'm hoping this PR can address that as well, e.g. by providing a mechanism to handle special types of errors differently from others.

Are there reasons you constructed the error as you did (e.g. not overwriting var error in the on('error') block, parsing & passing stderr on('close'))?

@unindented
Copy link
Collaborator

Regarding the error handling, I think I copied what electron-winstaller was doing at the time. If you think it can be simplified, feel free to create a new PR!

src/installer.js Outdated
if (err.name === 'ENOENT') {
var installer = process.platform === 'darwin' ? 'brew' : 'apt-get'

if (err.message.indexOf('fakeroot') > -1) {
Copy link
Member

Choose a reason for hiding this comment

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

you could check err.syscall for spawn fakeroot or spawn dpkg, I do something similar in Electron Packager: https://github.com/electron-userland/electron-packager/blob/6f5f2934ca19a384991cc44b6c83e35322cbcd9d/win32.js#L29

@unindented unindented merged commit e5a0ae1 into electron-userland:master Mar 26, 2017
@unindented
Copy link
Collaborator

Published version v0.5.1 with your changes. Thanks for your help @malept and @anulman!

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