Skip to content

fix(build_environment): re-raise exception for the JSON parse failure#1026

Merged
mergify[bot] merged 1 commit intopython-wheel-build:mainfrom
LalatenduMohanty:fix/get-distributions-unbound-error
Apr 6, 2026
Merged

fix(build_environment): re-raise exception for the JSON parse failure#1026
mergify[bot] merged 1 commit intopython-wheel-build:mainfrom
LalatenduMohanty:fix/get-distributions-unbound-error

Conversation

@LalatenduMohanty
Copy link
Copy Markdown
Member

Previously, if json.loads() failed, the except block logged the error but did not re-raise, causing an UnboundLocalError on the next line where mapping was undefined. Now the original exception is re-raised.

Closes: #1023

…JSON parse failure

Previously, if json.loads() failed, the except block logged the error
but did not re-raise, causing an UnboundLocalError on the next line
where `mapping` was undefined. Now the original exception is re-raised.

Closes: python-wheel-build#1023
Co-Authored-By: Claude <claude@anthropic.com>
Signed-off-by: Lalatendu Mohanty <lmohanty@redhat.com>
@LalatenduMohanty LalatenduMohanty requested a review from a team as a code owner April 6, 2026 04:14
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 6, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ca11387f-cc88-4097-a517-434d9bd789e0

📥 Commits

Reviewing files that changed from the base of the PR and between b5df8e2 and 2f588af.

📒 Files selected for processing (2)
  • src/fromager/build_environment.py
  • tests/test_build_environment.py

📝 Walkthrough

Walkthrough

The pull request fixes a bug in BuildEnvironment.get_distributions() where JSON deserialization failures caused an UnboundLocalError instead of propagating the actual exception. A single raise statement was added to re-raise caught exceptions, ensuring callers see the real json.JSONDecodeError. Corresponding test cases verify both the valid JSON path and invalid JSON exception handling.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: re-raising exceptions in get_distributions() when JSON parsing fails.
Description check ✅ Passed The description clearly explains the problem (UnboundLocalError due to swallowed exception), the solution (re-raise), and links to issue #1023.
Linked Issues check ✅ Passed The PR fully implements the fix specified in #1023: adds raise after logging to propagate the original exception, and includes two test cases covering valid and invalid JSON scenarios.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the error handling in get_distributions() and adding corresponding tests; no unrelated modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

@mergify mergify bot added the ci label Apr 6, 2026
Copy link
Copy Markdown
Contributor

@rd4398 rd4398 left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@mergify mergify bot merged commit 9a24ab8 into python-wheel-build:main Apr 6, 2026
39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: get_distributions() crashes with UnboundLocalError on JSON parse failure

2 participants