Skip to content

Conversation

@absolutely-vivid
Copy link

@absolutely-vivid absolutely-vivid commented Dec 12, 2025

  • I have added a news fragment under changelog.d/ (if the patch affects the end users)

closes #1698

Summary of changes

Running pip list in a broken or improperly configured environment can result in pip crashing without providing output. run_subprocess can eat that subprocess error leading to json.loads decoding 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.

Running `pip list` in a broken or improperly configured environment can
result in pip crashing without providing output. `run_subprocess` can eat
that subprocess error leading to `json.loads` decoding 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.
Failed to execute pip list - {cmd_run.args}. Process exited with return code
{cmd_run.returncode}.\n
stderr:\n
{"\t".join(cmd_run.stderr.split("\n"))}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The specifics of the exception message might need to be changed, particularly around this line. I wasn't sure what the preferred style is, so I erred on the side of caution and just added as much context to the exception message as I could

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Misleading exception when pip subprocess crashes

1 participant