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

Safely exit by throwing an error #546

Merged
merged 3 commits into from Nov 14, 2016
Merged

Safely exit by throwing an error #546

merged 3 commits into from Nov 14, 2016

Conversation

freitagbr
Copy link
Contributor

Fixes #483.

Instead of exiting the process with process.exit(1), simply throw an error. This way, the error can be caught by Node itself. If the error is not caught, the error is still printed, and the process exits with a 1.

@nfischer
Copy link
Member

nfischer commented Nov 2, 2016

Is there a way to make the message be part of the new stack trace? That would be even better.

@nfischer nfischer self-assigned this Nov 2, 2016
@freitagbr
Copy link
Contributor Author

Do you mean the 'ShellJS: internal error' message?

@nfischer
Copy link
Member

nfischer commented Nov 2, 2016

Do you mean the 'ShellJS: internal error' message?

Yeah, that's what I meant

@nfischer
Copy link
Member

nfischer commented Nov 3, 2016

@freitagbr is it standard to prepend to the message like that?

@freitagbr
Copy link
Contributor Author

freitagbr commented Nov 3, 2016

Probably not, so I will suggest a different option: changing the error name to ShellJSInternalError, rather than fiddling with the message itself.

@nfischer
Copy link
Member

nfischer commented Nov 3, 2016

@freitagbr that could work

@nfischer nfischer added this to the v0.8.0 milestone Nov 5, 2016
@freitagbr
Copy link
Contributor Author

I toyed around with the idea of creating an internal error class, but in this instance, I think just changing the name should suffice.

@nfischer nfischer changed the base branch from master to dev November 14, 2016 06:13
@nfischer
Copy link
Member

LGTM. Moving this to the dev branch since it's a breaking change.

Hopefully we don't have to worry about unexpected scenarios where you can't assign to properties of exception is caught. This approach should be perfectly fine for any real exception.

@nfischer nfischer merged commit bb2075c into shelljs:dev Nov 14, 2016
@nfischer nfischer added the breaking Breaking change label Nov 14, 2016
@freitagbr freitagbr deleted the no-process-exit branch November 14, 2016 09:27
@nfischer
Copy link
Member

@freitagbr it looks like we may have lost this commit on dev branch with a force push (I wish github supported auto merging). I'll just stick with manual merges instead of rebases to update dev branch.

Would you be able to redo this commit?

@freitagbr
Copy link
Contributor Author

Yeah, let me do redo this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking Breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants