Skip to content

[None][fix] missing-wheel SetupError raises UnboundLocalError on a stale from e - #18964

Closed
Anai-Guo wants to merge 1 commit into
NVIDIA:mainfrom
Anai-Guo:fix-setup-wheel-error-stale-from-e
Closed

[None][fix] missing-wheel SetupError raises UnboundLocalError on a stale from e#18964
Anai-Guo wants to merge 1 commit into
NVIDIA:mainfrom
Anai-Guo:fix-setup-wheel-error-stale-from-e

Conversation

@Anai-Guo

@Anai-Guo Anai-Guo commented Sep 9, 2026

Copy link
Copy Markdown

When a precompiled tar.gz does not contain a TensorRT-LLM/tensorrt_llm-*.whl member, extract_from_precompiled is meant to raise a clear SetupError. Instead it raises UnboundLocalError, because the raise ... from e refers to an e that is never bound on that path.

    else:
        ...
        try:
            urlretrieve(precompiled_location, filename=precompiled_path)
        except Exception as e:
            raise SetupError(
                f"Failed to get precompiled file from {precompiled_location}."
            ) from e

    if precompiled_path.endswith("tar.gz"):
        with tarfile.open(precompiled_path, "r:gz") as tar:
            for member in tar.getmembers():
                if fnmatch.fnmatchcase(member.name,
                                       "TensorRT-LLM/tensorrt_llm-*.whl"):
                    break
            else:
                raise SetupError(
                    f"Failed to get wheel file from {precompiled_path}.") from e

e is bound only by the except Exception as e: above, and it is unbound at the for/else in every case:

  • precompiled_location is a local file — the else: download branch never runs, so e was never assigned;
  • the download branch ran and succeeded — no exception was caught;
  • the download branch ran and failed — it already raised, so this line is unreachable.

On top of that, Python 3 deletes the as target at the end of the except block, so e would not survive even if it had been bound.

Reproduction

Building a tar.gz that holds no matching wheel and calling extract_from_precompiled on it:

result
before UnboundLocalError: cannot access local variable 'e' where it is not associated with a value
after SetupError: Failed to get wheel file from /tmp/.../precompiled.tar.gz.

The intended diagnostic is restored, and the operator finds out which archive was bad instead of getting an UnboundLocalError from setup.py.

Fix

Drop the stale from e. There is no active exception to chain here — this is a plain validation failure. The other two from e sites in this file are inside their own except blocks and are left untouched.

🤖 Generated with Claude Code

Dev Engineer Review

setup.py now raises SetupError when an archive lacks a matching wheel. The change removes invalid exception chaining and does not alter other exception paths.

QA Engineer Review

No test changes.

Per-File QA Perspective

  • setup.py: Verify that archives without a matching wheel raise SetupError instead of UnboundLocalError.

In setup.py's extract_from_precompiled, the "Failed to get wheel file"
SetupError chains `from e`, but `e` is only bound by the `except Exception
as e` of the download branch above. On the for/else path `e` is always
unbound: a local precompiled file skips the download branch entirely, a
successful download catches nothing, and a failed download already raised.
Python 3 also deletes the `as` target at the end of the except block.

A tar.gz without a TensorRT-LLM/tensorrt_llm-*.whl member therefore fails
with `UnboundLocalError: cannot access local variable 'e'` instead of the
intended SetupError naming the bad archive.

Signed-off-by: Tai An <antai12232931@outlook.com>
@Anai-Guo
Anai-Guo requested a review from a team as a code owner September 9, 2026 10:17
@coderabbitai

coderabbitai Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 7a05b30b-1779-4594-af68-d1956af99e1e

📥 Commits

Reviewing files that changed from the base of the PR and between 96a25c4 and 98aa7e8.

📒 Files selected for processing (1)
  • setup.py

Included review availability: Your plan provides up to 12 included reviews per hour; 9 remain after this review.


Walkthrough

The setup process now raises SetupError without chaining the original exception when a tarball contains no wheel.

Changes

Setup error handling

Layer / File(s) Summary
Missing-wheel error handling
setup.py
The missing-wheel SetupError no longer uses exception chaining.

Priority: ⬇️ Low

Estimated code review effort: 1 (Trivial) | ~2 minutes

Merge Risk: ⚪ Minimal · up to 98aa7

Tarballs without a matching wheel now report the intended setup error instead of failing with an unbound local variable error. No current merge-blocking risk remains.

Suggested reviewers: atrifex

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the fix: removing stale exception chaining so a missing wheel raises SetupError instead of UnboundLocalError. It follows the required [None][fix] format.
Description check ✅ Passed The description clearly explains the issue, root cause, affected code path, reproduction, expected behavior, and fix. It does not include explicit Test Coverage or PR Checklist sections, but the relev…
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@tburt-nv

tburt-nv commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

Hi @Anai-Guo, thanks for the contribution! Another PR has already been opened with an identical diff, so I'll close this one: #18703.

@tburt-nv tburt-nv closed this Sep 9, 2026
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.

2 participants