Fix #2524: improve user experience when trying to pull models from Hu... - #2595
Conversation
When pulling from HuggingFace, a 404 from the API (e.g. file not found) was caught and the code fell through to the CLI fallback path. Since Huggingface.get_cli_download_args() always raises NotImplementedError, users saw "huggingface cli download not available" even when the CLI was installed. Re-raise the original exception when get_cli_download_args() is not implemented so the actual error (e.g. HTTP 404) is shown. Signed-off-by: Zakir Jiwani <108548454+JiwaniZakir@users.noreply.github.com>
Reviewer's GuideAdjusts HF-style model pull logic to surface the original HTTP error instead of a misleading NotImplementedError and adds a regression test to lock in the new behavior. File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- Catching a bare
NotImplementedErroraroundget_cli_download_argswill also intercept any futureNotImplementedErrorraised inside that code path for unrelated reasons; consider narrowing the exception source (e.g., by moving the try/except closer to where the CLI availability is checked or introducing a more specific custom exception). - The test’s manual stubbing of
TemporaryDirectory.__enter__/__exit__is a bit brittle; usingtempfile.TemporaryDirectoryas-is with a real temporary directory, or a small helper/context manager to encapsulate this setup, would make the test easier to follow and less dependent on implementation details.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Catching a bare `NotImplementedError` around `get_cli_download_args` will also intercept any future `NotImplementedError` raised inside that code path for unrelated reasons; consider narrowing the exception source (e.g., by moving the try/except closer to where the CLI availability is checked or introducing a more specific custom exception).
- The test’s manual stubbing of `TemporaryDirectory.__enter__`/`__exit__` is a bit brittle; using `tempfile.TemporaryDirectory` as-is with a real temporary directory, or a small helper/context manager to encapsulate this setup, would make the test easier to follow and less dependent on implementation details.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Code Review
This pull request introduces a try-except block in hf_style_repo_base.py to handle NotImplementedError during model pulls and adds a regression test. A bug was introduced where an undefined variable e is raised in the exception handler. Review feedback suggests adding a descriptive error message before re-raising the exception to improve user context and maintain consistency.
| try: | ||
| conman_args = self.get_cli_download_args(tempdir, model) | ||
| except NotImplementedError: | ||
| raise e from None |
There was a problem hiding this comment.
For consistency with the case where the CLI tool is not available at all (lines 362-364), it would be beneficial to also print an error message here before re-raising the original exception. This would inform the user that a fallback to CLI download was attempted but failed because it's not implemented, providing more context for the failure.
perror(f"URL pull failed and {self.get_cli_command()} download not available")
raise e from None|
A friendly reminder that this PR had no activity for 30 days. |
Closes #2524
Surfaces the original HTTP error (e.g. 404) when pulling from Hugging Face instead of masking it with a misleading
NotImplementedError.Changes
ramalama/hf_style_repo_base.py—HFStyleRepoModelpull pathWrapped the call to
self.get_cli_download_args(tempdir, model)in atry/except NotImplementedErrorblock. Whenget_cli_download_argsraisesNotImplementedError(the "huggingface cli download not available" path), the code now re-raisese— the original exception from the earliercreate_repositoryattempt — viaraise e from None, so the real failure reason reaches the user.test/unit/test_transport_factory.py— new regression testAdded
test_hf_pull_surfaces_http_error_not_notimplementederror, which patchescreate_repositoryto raise aKeyErrorcontaining a 404 message string, patchesavailableto returnTrue(simulating an installed CLI), and asserts thatmodel.pull()propagates theKeyErrorrather than swallowing it. ImportsMagicMock,PropertyMock, andpatchfromunittest.mockwere added to support the new test.Motivation
When
create_repositoryfailed with an HTTP 404 (model file not found on HF), the exception was stored ineand control fell through to the CLI download path. There,get_cli_download_argsraisedNotImplementedErrorwith the generic "huggingface cli download not available" message, which replaced the informative HTTP error. Users withhuggingface_hubcorrectly installed still saw the misleading CLI-missing error with no indication that the model path itself was wrong.Testing
The new unit test covers the regression directly:
The test confirms that a
KeyErrorcontaining"HTTP Error 404: Not Found"propagates out ofpull()unchanged, and thatNotImplementedErrordoes not surface in its place.This PR was created with AI assistance (Claude). The changes were reviewed by quality gates and a critic model before submission.
Summary by Sourcery
Surface original Hugging Face HTTP errors when model pulls fail instead of masking them with a generic NotImplementedError from the CLI download path.
Bug Fixes:
Tests: