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

[BUG] "npm outdated --json" should not have exit code 1 #1109

Closed
danawoodman opened this issue Apr 4, 2020 · 10 comments
Closed

[BUG] "npm outdated --json" should not have exit code 1 #1109

danawoodman opened this issue Apr 4, 2020 · 10 comments
Labels
Bug thing that needs fixing

Comments

@danawoodman
Copy link

What / Why

In order to easily parse the output of npm outdated --json, this command should always exit cleanly (unless of course an actual error occurs).

The reason for this is that because --json exits if there are outdated dependencies, using something like exec/execFile to get the stdout fails to work as expected and you instead have to parse error output and remove the first line of the output before parsing the JSON response body.

Unless I'm mistake, then JSON output is mean to be parsed, so having a failure output for the perfectly valid scenario of having out of date packages, seems problematic to me.

I suggest that if a users passes --json to npm outdated, the command always exits cleanly unless an actual error occurs.

Example of the output of running npm outdated --json in node and getting an error instead of JSON output:

When

n/a

Where

CLI
npm: 6.13.7
node: v13.10.1

How

Current Behavior

See description

Steps to Reproduce

Run npm outdated --json on a project without out of date dependencies and check error code.

Expected Behavior

Don't return an error code if packages are out of date if --json flag is provided.

Who

All CLI users

References

n/a

@ljharb
Copy link
Collaborator

ljharb commented Apr 4, 2020

Are you sure the json isn’t on stdout, and the error on stderr, which would enable you to easily pipe or separate the json output?

@danawoodman
Copy link
Author

I logged out stdout from the execFile output, so yeah I'm pretty sure it is not coming out on stdout. You can also run npm outdated --json on the console and check output to verify my above assertion is true 👍

@ljharb
Copy link
Collaborator

ljharb commented Apr 4, 2020

It seems reasonable to me that, unrelated to exit code, a command with --json should only ever output json on stdout.

@danawoodman
Copy link
Author

@ljharb sweet, I'm glad you agree 😄

I assume this is considered a breaking change tho?

@ljharb
Copy link
Collaborator

ljharb commented Apr 7, 2020

Seems like a patch to me, but I don't make those decisions here :-)

@danawoodman
Copy link
Author

Well technically it is a breaking change right? Like if people expected the default output to have exit 1 it would break for them right? Not that I really care, it would just be cool if it was fixed 😄

@jsgv
Copy link

jsgv commented Apr 29, 2020

Same thing happens in the case of a Makefile.

I understand that at some point that was the desired functionality, but npm outdated should not return an error.

A new package version being available is not an error.

Or at least it should respect the --silent flag.

npm-outdated

@josh-hemphill
Copy link

So now it outputs everything to stdout, but still returns code 1, preventing a sub-process in node from being able to parse the result.

@darcyclarke
Copy link
Contributor

npm v6 is no longer in active development; We will continue to push security releases to v6 at our team's discretion as-per our Support Policy.

If your bug is preproducible on v7, please re-file this issue using our new issue template.

If your issue was a feature request, please consider opening a new RRFC or RFC. If your issue was a question or other idea that was not CLI-specific, consider opening a discussion on our feedback repo

Closing: This is an automated message.

@VitiaCatDragon
Copy link

npm version 8.5.5.
command "npm outdated" returning code 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing
Projects
None yet
Development

No branches or pull requests

6 participants