-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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] npm info exits with zero exit code if package@version is not found #4964
Comments
I'd indeed expect an error, just like |
|
yes, they're aliases of the same command. |
This fixes an error in npm show. When calling npm show with a specific version of a package that does not exist, it does not show anything and gives a zero exit code. This has been changed: now it gives a 404 Error similar to if the package does not exist. Can be tested with npm show express@5.0.0 (local: node bin/npm-cli.js info express@5.0.0) Fixes #4964 Co-authored-by: @lukaskuhn-lku Co-authored-by: @ljharb
This is a breaking change for us, we were relying on the behavior that nothing was output and a successful exit code was returned for a package/version that didn't exist |
@simoneb conversely, returning nothing is a breaking change for us. It's not clear when the regression was introduced though but it could be reasonable to introduce a feature to opt-in to this behavior. That said you can always redirect the output to /dev/null and add || true to get the behavior you want :) On our side, maybe there's another way to detect if a package was not published in one line of bash... |
how is a breaking change something that has been that way for a long time? |
@simoneb You're not wrong in that respect. I wasn't aware how long the unexpected behavior had been around for and wrote some code in the past few months that relied on the new behavior assuming it behaved this way from the start. |
This is the inevitable struggle - if you're relying on a bug, the bug fix is a breaking change for you. |
Who decided it was a bug? Until this issue was reported this was the behavior of that command since a long time and nothing suggested that it was a bug. In the best case it was an undocumented behavior. |
@simoneb ok, i'll indulge you :-) what would be the failure case for this command if not "nothing was found"? |
I accept the new behavior, I'm not implying that it should be changed back to what it was and we have already adapted our affected codebase to handle both old and new behavior. but I thought it was worth reporting as this is a breaking change introduced in a minor semver release. |
Right - what I'm saying tho is, that since there's no reasonable argument to be made for the previous behavior, only for the new behavior, that's why I'd consider it a bug, no matter how long it's been around. |
No argument advocating the previous behavior as right on my side either, just reporting the breaking change, that's all ✌️ |
Ref: #5035 (comment) @ljharb this just hit us over in the Electron release team as a result of some semi-automated npm updates our release infrastructure pulled in the new npm and this broke our release logic in a relatively annoying way that was quite hard to deal with. I agree with everything you said above specifically:
but I think there is a line to be drawn that if the old behavior was not entirely unreasonable and could be relied upon, a change to "improve" that behavior should be marked as breaking and ideally would have gone out in |
@MarshallOfSound that's a fair counterpoint. |
To give a little context around this from the Error codes and terminal output are something that (As an aside, there's always the option to add a flag, which has its own tradeoffs I'll save for another thread.) I appreciate both @simoneb and @MarshallOfSound adding their experience to the thread. At the very least, it will help us inform future decisions around stuff like this. To put it on the record here: exit codes are definitely part of the |
Is there an existing issue for this?
This issue exists in the latest npm version
Current Behavior
If I do:
Then the exit code is 0, but no output from
npm info
is printed, as8.7.1
of npm doesn't exist. I would expectnpm info
to give a non-zero exit code if the package at the specified version doesn't exist. If the package doesn't exist at all, thennpm info
does have a non-zero exit code (with logs telling you it doesn't exist)Expected Behavior
Would log a message saying the specified version of that package doesn't exist, and exit with a non-zero exit code, much like for non-existent packages.
Steps To Reproduce
See above, assuming
npm@8.7.1
hasn't been published in the meantime.Environment
The text was updated successfully, but these errors were encountered: