Make list_installed_packages handle pip errors (#1698) #1699
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.
changelog.d/(if the patch affects the end users)closes #1698
Summary of changes
Running
pip listin a broken or improperly configured environment can result in pip crashing without providing output.run_subprocesscan eat that subprocess error leading tojson.loadsdecoding an empty string, resulting in pipx crashing with a misleading error about malformed JSON.This commit explicitly checks the return code of the pip process, providing a friendlier error message for easier debugging.
Test plan
I don't think testing is needed here, the commit just changes which exception is raised in this edge case.