Skip to content

Report install errors and failures in JSON format - #14083

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

Report install errors and failures in JSON format#14083
Vishvendra47 wants to merge 4 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

@sepehr-rs sepehr-rs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hi @Vishvendra47, thanks for the contribution!
FWIW, my understanding from the discussion in #11316 is that maintainers were looking for a design proposal before implementation, and this PR seems to diverge from some of the design points discussed there. In particular, the proposed error codes were intended to be stable user-facing identifiers (e.g. resolution_impossible) rather than raw pip exception class names like DistributionNotFound.

It might be worth revisiting the error schema/design in the issue first, especially since this touches pip's error handling model.

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.

3 participants