Skip to content

Report install errors and failures in JSON format#14083

Open
Vishvendra47 wants to merge 3 commits into
pypa:mainfrom
Vishvendra47:feature/11316-json-report-errors
Open

Report install errors and failures in JSON format#14083
Vishvendra47 wants to merge 3 commits into
pypa:mainfrom
Vishvendra47:feature/11316-json-report-errors

Conversation

@Vishvendra47

Copy link
Copy Markdown

This PR addresses issue #11316 by ensuring that when pip install is executed with the --report option, any installation or dependency resolution errors are outputted in JSON format instead of terminating with plain text logs on stdout.

Changes

  1. src/pip/_internal/commands/install.py:
    • Initialized requirement_set = None before the installation try-block.
    • Added a dedicated exception handler for (InstallationError, CommandError, InstallWheelBuildError).
    • If --report is specified, the handler creates an InstallationReport (with whatever requirements were parsed up to that point), converts it to a dictionary, injects an error dictionary containing code (the exception class name) and description (the error message), outputs it (to stdout or a file), and then re-raises the exception.
  2. tests/functional/test_install_report.py:
    • Added test_install_report_error and test_install_report_error_stdout to verify the error reporting output.
  3. News Fragment:
    • Added news/11316.feature.rst news fragment file.

Output Example

Running pip install "pip-tools==6.8.0" "pip==20.1" --dry-run --report - now outputs:

{
  "version": "1",
  "pip_version": "26.2.dev0",
  "install": [],
  "environment": { ... },
  "error": {
    "code": "DistributionNotFound",
    "description": "ResolutionImpossible: ..."
  }
}

@Vishvendra47

Copy link
Copy Markdown
Author

pre-commit.ci autofix

@ichard26 ichard26 added the skip PR template check Silence the PR template check in CI label Jul 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided skip PR template check Silence the PR template check in CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants