nix search --json: Don’t fail for empty result set #3448
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I'm using
nix search --json
to generate a list of all the packages available for installation. I noticed that I cannot test this command for failure, because...it always fails.Specifically, it always outputs "no results for the given search term(s)", even after outputting a huge list of packages, and it always results in an exit code of 1.
Is this intentional? I see two cases to handle here:
nix search
ornix search --json
. This is valid and even an example in the manpage. In this case, I think you never want to fail.--json
isn't provided. If it is, I think it's a matter of preference. I personally wouldn't let it fail. The script you're writing can process the JSON and check for emptiness.Regarding the code: Since
results
is apparently not filled in json mode, testing it for emptiness doesn't make much sense. This PR only tests this in plain-text mode as a first fix to the problem.