Skip to content

[Bugfix] Fix wrong exception type and unbound variable guard - #5063

Merged
Wauplin merged 2 commits into
huggingface:mainfrom
vector15-05:main
Oct 2, 2026
Merged

Wauplin merged 2 commits into
huggingface:mainfrom
vector15-05:main

Conversation

@vector15-05

@vector15-05 vector15-05 commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Fixes two minor bugs:

  • serialization/_torch.py: load_torch_model raised ValueError when the checkpoint path doesn't exist, but the docstring documents FileNotFoundError. Downstream code catching FileNotFoundError would miss this. Changed to FileNotFoundError.
  • repocard_data.py: model_index_to_eval_results([]) crashed with UnboundLocalError because name is only assigned inside the loop. Added an early guard that raises a descriptive ValueError for empty input.

No behavior change for valid inputs. ruff check, ruff format --check, and the generated-file checks (check_static_imports, generate_async_inference_client, generate_cli_reference) pass.

Note

Low Risk

Two minimal fixes (one line changed, two lines added). No API surface or signature changes.

_torch.py — ValueError → FileNotFoundError on line 440. Only affects the already-failing case when the path doesn't exist, now matches the documented exception type.

repocard_data.py — Added guard if not model_index: raise ValueError(...) before the loop. Prevents UnboundLocalError on empty model_index lists (e.g. from a model card with model-index: []).

Closes #5062
Closes #5061


Note

Low Risk
Narrow exception-type and input-validation fixes only on already-failing paths; no API signature changes and valid inputs behave the same.

Overview
Two small error-handling fixes with no change for valid inputs.

load_torch_model now raises FileNotFoundError when the checkpoint path is missing, matching the documented API and letting callers that catch FileNotFoundError handle missing paths correctly (previously ValueError). The ValueError docstring entry is narrowed to checkpoint format issues only.

model_index_to_eval_results rejects an empty model_index up front with a clear ValueError instead of failing later with UnboundLocalError when model-index: [] appears on a model card.

Tests cover both behaviors.

Reviewed by Cursor Bugbot for commit 8f4996f. Bugbot is set up for automated code reviews on this repo. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want higher recall? High effort reviews run extra passes and find more bugs. A team admin can switch effort levels in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 9f57599. Configure here.

@bot-ci-comment

bot-ci-comment Bot commented Oct 2, 2026

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@Wauplin
Wauplin merged commit c31df86 into huggingface:main Oct 2, 2026
9 of 27 checks passed
@huggingface-hub-bot

Copy link
Copy Markdown
Contributor

This PR has been shipped as part of the v2.2.0 release.

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.

model_index_to_eval_results crashes on empty list Wrong exception type in load_torch_model

2 participants