-
Notifications
You must be signed in to change notification settings - Fork 559
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refacto error parsing (HfHubHttpError) #2474
Conversation
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. |
This comment was marked as duplicate.
This comment was marked as duplicate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall LGTM! Will take a second pass
@@ -11,117 +11,117 @@ | |||
RepositoryNotFoundError, | |||
RevisionNotFoundError, | |||
) | |||
from huggingface_hub.utils._errors import REPO_API_REGEX, hf_raise_for_status | |||
from huggingface_hub.utils._http import REPO_API_REGEX, X_REQUEST_ID, _format, hf_raise_for_status |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the tests be moved to https://github.com/huggingface/huggingface_hub/blob/main/tests/test_utils_http.py for consistency with the rest of the codebase?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the refactor @Wauplin!
assert context.exception.response.status_code == 404 | ||
assert "Request ID: 123" in str(context.exception) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity, why the change from self.assertEqual
/self.assertIn
to blank asserts with boolean statements? For consistency with new tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly for consistency yes. I'm only doing it when I'm adding tests next to existing ones (see related convo on slack -private-)
…gface_hub into refacto-error-parsing
Thanks for the review @LysandreJik! I addressed @osanseviero 's comment and resolved the merge conflicts. Failing CI is unrelated so I'm merging now. |
(sorry for long PR, most of it is moving logic around)
Done as part of #2069.
This PR updates how
HfHubHttpError
is formatted. With #2069, all errors are now defined insrc/huggingface_hub/errors.py
with no logic it the module. Before this PR, the logic to format the error message from a server response was split betweenHfHubHttpError.__init__
andhf_raise_for_status
. This should not have being split in the first place (harder to read/investigate)What does this PR do?
HfHubHttpError.__init__
tohf_raise_for_status
. This is the only way to instantiate aHfHubHttpError
anywayhf_raise_for_status
definition inside./utils/_http.py
where it belongs instead of./utils/_errors.py
./utils/_errors.py
module to avoid confusion with./errors.py
where all exceptions are definedrequest_id
/server_message
as attributes. I'm pretty sure it's not used by anyone but at least it keeps backward compatibility.self.assertEquals...
)In the end, sorry for the long diff because 95% of it is simply moving some logic around.