-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
[BUG] Inconsistency between calls to npm on node.js 16.x #3871
Comments
More details: Call to npm outdated having outdated global packages with node 16.11 and default npm 8.0.0
with node 16.10 and default npm 7.24.0
As you can see, exit status code has changed. When there are outdated packages, npm 7.24.0 exit with an exit status of 0, and npm 8.0.0 exit with an exit status of 1. Call to npm outdated without having outdated global packages with node 16.11 and default npm 8.0.0
with node 16.10 and default npm 7.24.0
So, when there are no outdated packages, both exit with status code 0. Summary I understand that exit error code must be 0 if it's ok, or 1-255 if there are an error. The usual way to do that should be to exit with an error code of 0 (if there are no error), and then, if you want to know if there are outdated packages or not, read the return string (as showed on the examples), and if the string is a void string, there are no outdated packages. |
This changed in npm v7.24.2 - npm v7.24.1 and below exit zero in this case. |
I'm astonished. without outdated packages
with outdated packages
|
@nassau-t that depends on what mental model you have of this command. If it's "get me the results of an outdated check", then it should return 0, because it got the results. If it's "tell me if everything is up to date", then it absolutely should return nonzero when there's nonzero outdated deps. |
I will prove it empirically:
What do you see here? Because I see an error. In other words, exit status code has nothing to do with what you think or what you expect. It only makes reference to if the execution is ok or there is an error in the execution, nothing more. |
Right - but “the execution” is subjective. |
No, it's not subjective. It's not subjective because an exit status code of 0 is execution were ok, and an exit status code of 1-255 is there were an error on the execution. Because of that, the system says there is an error. It's not me, and neither are you. It's totally objective because that is the rule. Look at the example above, I have proved it. |
There is no rule, it’s merely a convention, and every tool is always free to choose as they see fit. An analogue might be, when i do |
I will repeat the empirical proof again.
What do you see here? Because I see an error. I repeat: exit status code has nothing to do with what you think or what you expect. It only makes reference to if the execution is ok or there is an error in the execution, nothing more. |
And in one view, when there are outdated packages, there’s an error in execution, and one absolutely and only wants the thrown error in your case. I’m not actually arguing in favor of the exit code - I’m objecting to the incorrect assertion that there’s an obviously correct answer here. |
An error of execution could be if there weren't an internet connection, or if it was impossible to get the list of packages... If there are outdates packages, that is not an error of execution. It was possible to get packages, to compare packages, to return a list of outdates packages... There weren't any error execution. If you want to return the string "HEY, THERE ARE OUTDATED PACKAGES!!", you can do it. But you can not return an exit code status of 1 because there hasn't been any error of execution. So you are lying. It must return 0. |
What you’re describing is not a rule - not something that anyone “must” do. It’s just a convention. Accusing someone of lying is a violation of npm’s CoC; assume good faith. |
Name it a rule, a convention... The fact is that all computer languages work this way. I'm not acussing you of lying, I accusing npm outdated to be lying when it return a status exit code of 1 when there had not been any error at all. |
Ah, sorry then, i misread. All things do not work this way - i use and create plenty of CLI tools that return a nonzero code when the conceptually requested action couldn’t be completed, even if there’s no error in execution. That’s what’s maximally useful, which is much, much more important than ideological purity, especially of something that is merely a convention. |
npm outdated is lying. There weren't any error because it can return the list of outdated packages, not error connection, not error reading packages... But it have returned 1 in the execution. I don't have it in my profile (because I think that arguments must prevail) but I'm also a software engineer. I say this because I am not here to make a mess, but because I firmly believe in what I am defending. |
I think that it is very important in a system that all commands works in the same way. It's like unix design. You can put pieces together. But if any command make it's own rules or conventions, it's a mess. Because every single piece work in a different way. npm outdated can return a 0 or 1, it's not a big problem. The problem is that any language that executes npm outdated are expecting a exit code status of 0 if all works well. So if it return a 1-255 exit code status, they will interpret that there has been an error (network, disk...). So, you can put pieces together, but you will have to handle exceptions in every tool that don't work as expected. |
I don’t agree with that expectation. If you have that expectation generically, your expectations are what’s broken. |
I don't use And I repeat, that are not my expectations, are the expectations of any language, as you can see again in the example. Nodejs throws an error. It's not me that says there is an error. It's nodejs who says me that there is an error because it runs the catch block.
And I repeat, "there ara outdated packages" is only and answer to the question "are there outdated packages?". An answer. Npm outdated can't say: as there are outdated packages I will return an error during the execution, because it's lying. There wasn't any error during execution. So npm 7.24.0 was working well (on npm outdated), and 8.0.0 isn't. |
|
Since this behavior has been requested both ways before (#2556 #3844), I think it would be best if it went through the RFC process so we can discuss it further. @nassau-t Would you be willing to open an RFC with your reasoning from this issue and we can have further discussion about this? For now, I am going to close this issue since it will be more productive to have the discussion over there. |
Created RFC npm/rfcs#473 |
Is there an existing issue for this?
Current Behavior
A call to npm outdated, if there are outdated packages, throws an exit code status of 1
Expected Behavior
It was working like this in the the node.js 16.x branch until 16.11.
Steps To Reproduce
In this environment...
Windows 10 pro x64. Node.js v16.11.0 (with included npm v8.0.0)
With this config...
A system with global outdated packages.
Run '...'
require('child_process').execSync('npm outdated -g --depth=0')
See error...
Throws a exit status code of 1
Environment
The text was updated successfully, but these errors were encountered: