huggingface / huggingface_hub

The official Python client for the Huggingface Hub.
https://huggingface.co/docs/huggingface_hub
Apache License 2.0
2.12k stars 556 forks source link

Refacto error parsing (HfHubHttpError) #2474

Closed Wauplin closed 2 months ago

Wauplin commented 3 months ago

(sorry for long PR, most of it is moving logic around) Done as part of https://github.com/huggingface/huggingface_hub/issues/2069.

This PR updates how HfHubHttpError is formatted. With https://github.com/huggingface/huggingface_hub/issues/2069, all errors are now defined in src/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 between HfHubHttpError.__init__ and hf_raise_for_status. This should not have being split in the first place (harder to read/investigate)

What does this PR do?

In the end, sorry for the long diff because 95% of it is simply moving some logic around.

HuggingFaceDocBuilderDev commented 3 months ago

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 commented 3 months ago

As spotted by @osanseviero, this will break an import in datasets-viewer test suite @severo: https://github.com/huggingface/dataset-viewer/blob/e8e0edfb3e4b76173675d6637c170441abd42141/e2e/tests/utils.py#L15

You can already fix this by doing from huggingface_hub.utils import hf_raise_for_status.

Wauplin commented 2 months ago

Thanks for the review @LysandreJik! I addressed @osanseviero 's comment and resolved the merge conflicts. Failing CI is unrelated so I'm merging now.