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

[Feature proposal] Distinguishing between error strings and error numbers #179

Closed
ehmicky opened this issue Feb 28, 2019 · 14 comments
Closed

Comments

@ehmicky
Copy link
Collaborator

ehmicky commented Feb 28, 2019

At the moment result.code is either a string like EACCES, an integer like 13 or undefined.

It would be nice to split this property into two: code for the string and errno for the integer.

This would be a breaking change if the name code is re-used. Otherwise we can pick another property name.

If this sounds good, I will submit a PR.

@sindresorhus
Copy link
Owner

sindresorhus commented Feb 28, 2019

Ah yeah... I should not have reused .code for something different.

I don't want to do a breaking change just for this, so I suggest we add a .exitCode property. I prefer that over .errno. .errno in Node.js can be both a string and a number.

And in the next major version, we stop putting the exit code on the .code property.

@ehmicky
Copy link
Collaborator Author

ehmicky commented Feb 28, 2019

Sounds good.

So code is currently either string or integer. Should exitCode be string? Which property name should be for integer?

@sindresorhus
Copy link
Owner

.exitCode should be an integer. The exit code the process excited with.

@ehmicky
Copy link
Collaborator Author

ehmicky commented Feb 28, 2019

Since code can be either a string or an integer, should there a third property that can only be a string?

@sindresorhus
Copy link
Owner

What would it contain? Example?

@ehmicky
Copy link
Collaborator Author

ehmicky commented Feb 28, 2019

For example code currently can be either a string ("EACCES"), a positive integer (13) or undefined.
exitCode will only be a positive integer (13) or undefined.
A third property could be only a string ("EACCES") or undefined.

@sindresorhus
Copy link
Owner

A third property could be only a string ("EACCES") or undefined.

Do you have any use-case for this? You could mostly compare .code to something anyway, in which the type doesn't matter.

@ehmicky
Copy link
Collaborator Author

ehmicky commented Mar 4, 2019

The use case would be if a user wants to print the signal name but not number. Some users might consider that more user-friendly. Also signal names are cross-platform, whereas signal numbers aren't.

@sindresorhus
Copy link
Owner

Alright, any suggestion on what to name this string-only property?

@ehmicky
Copy link
Collaborator Author

ehmicky commented Mar 6, 2019

code (integer or string), exitCode (integer), exitName (string)?
Or code (integer or string), codeNumber (integer), codeName (string)?

@sindresorhus
Copy link
Owner

I think it should be exitCode for the number, since that's what it's called outside the Node.js ecosystem too. As for the string, maybe exitCodeName or exitCodeId?

@ehmicky
Copy link
Collaborator Author

ehmicky commented Mar 6, 2019

code (integer or string), exitCode (integer), exitCodeName (string) sounds good, I can open a PR.

Should code be marked as deprecated and removed in next major release or not? Users will be able to do exitCodeName || exitCode if they want. Otherwise having a single type might be better for them.

@sindresorhus
Copy link
Owner

code (integer or string), exitCode (integer), exitCodeName (string) sounds good, I can open a PR.

👍

Should code be marked as deprecated and removed in next major release or not?

No, I think it should stay, since users are used to it from Node.js core errors.

@ehmicky
Copy link
Collaborator Author

ehmicky commented Mar 7, 2019

PR at #187

@ehmicky ehmicky closed this as completed Mar 7, 2019
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

No branches or pull requests

2 participants