Voice et bot modif

This commit is contained in:
pi 2026-06-16 17:09:34 +00:00
parent 189d56026b
commit 7333a22bcd
10774 changed files with 634644 additions and 933308 deletions

View file

@ -1,7 +1,6 @@
"""Contains all custom errors."""
from pathlib import Path
from typing import Optional, Union
from httpx import HTTPError, Response
@ -12,9 +11,9 @@ from httpx import HTTPError, Response
class CacheNotFound(Exception):
"""Exception thrown when the Huggingface cache is not found."""
cache_dir: Union[str, Path]
cache_dir: str | Path
def __init__(self, msg: str, cache_dir: Union[str, Path], *args, **kwargs):
def __init__(self, msg: str, cache_dir: str | Path, *args, **kwargs):
super().__init__(msg, *args, **kwargs)
self.cache_dir = cache_dir
@ -30,6 +29,19 @@ class LocalTokenNotFoundError(EnvironmentError):
"""Raised if local token is required but not found."""
# OIDC ERRORS
class OIDCError(Exception):
"""Raised when keyless CI/CD auth via OIDC token exchange ("Trusted Publishers") cannot proceed.
Typically because `HF_OIDC_RESOURCE` is set but no id token is available: not running in a
supported CI provider and `HF_OIDC_ID_TOKEN` is unset.
See https://huggingface.co/docs/hub/trusted-publishers.
"""
# HTTP ERRORS
@ -45,7 +57,7 @@ class HfHubHTTPError(HTTPError, OSError):
sent back by the server, it will be added to the error message.
Added details:
- Request id from "X-Request-Id" header if exists. If not, fallback to "X-Amzn-Trace-Id" header if exists.
- Request ID sourced from headers in order of precedence: "X-Request-Id", "X-Amzn-Trace-Id", "X-Amz-Cf-Id".
- Server error message from the header "X-Error-Message".
- Server error message if we can found one in the response body.
@ -72,9 +84,13 @@ class HfHubHTTPError(HTTPError, OSError):
message: str,
*,
response: Response,
server_message: Optional[str] = None,
server_message: str | None = None,
):
self.request_id = response.headers.get("x-request-id") or response.headers.get("X-Amzn-Trace-Id")
self.request_id = (
response.headers.get("x-request-id")
or response.headers.get("X-Amzn-Trace-Id")
or response.headers.get("x-amz-cf-id")
)
self.server_message = server_message
self.response = response
self.request = response.request
@ -86,7 +102,7 @@ class HfHubHTTPError(HTTPError, OSError):
@classmethod
def _reconstruct_hf_hub_http_error(
cls, message: str, response: Response, server_message: Optional[str]
cls, message: str, response: Response, server_message: str | None
) -> "HfHubHTTPError":
return cls(message, response=response, server_message=server_message)
@ -167,6 +183,23 @@ class HFValidationError(ValueError):
"""
class HfUriError(ValueError):
"""Raised when an `hf://...` URI is malformed.
See [`parse_hf_uri`] and the
[HF URIs reference](https://huggingface.co/docs/huggingface_hub/main/en/package_reference/hf_uris)
for the canonical syntax.
Inherits from [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError).
"""
def __init__(self, uri: str, msg: str):
self.uri = uri
self.msg = msg
full_msg = f"Invalid HF URI '{uri}'. {msg}" if uri else f"Invalid HF URI. {msg}"
super().__init__(full_msg)
# FILE METADATA ERRORS
@ -181,6 +214,34 @@ class FileMetadataError(OSError):
"""
# BUCKET ERRORS
class BucketNotFoundError(HfHubHTTPError):
"""
Raised when trying to access a bucket that does not exist.
Attributes:
bucket_id (`str` or `None`):
The bucket id (namespace/name) that was not found, if it could be determined from the request URL.
Example:
```py
>>> from huggingface_hub import bucket_info
>>> bucket_info("<non_existent_bucket>")
(...)
huggingface_hub.errors.BucketNotFoundError: 404 Client Error. (Request ID: XXX)
Bucket Not Found for url: https://huggingface.co/api/buckets/namespace/name.
Please make sure you specified the correct bucket id (namespace/name).
If the bucket is private, make sure you are authenticated and your token has the required permissions.
```
"""
bucket_id: str | None = None
# REPOSITORY ERRORS
@ -189,6 +250,12 @@ class RepositoryNotFoundError(HfHubHTTPError):
Raised when trying to access a hf.co URL with an invalid repository name, or
with a private repo name the user does not have access to.
Attributes:
repo_id (`str` or `None`):
The repo id that was not found, if it could be determined from the request URL.
repo_type (`str` or `None`):
The repo type ("model", "dataset", or "space"), if it could be determined from the request URL.
Example:
```py
@ -199,11 +266,14 @@ class RepositoryNotFoundError(HfHubHTTPError):
Repository Not Found for url: https://huggingface.co/api/models/%3Cnon_existent_repository%3E.
Please make sure you specified the correct `repo_id` and `repo_type`.
If the repo is private, make sure you are authenticated.
If the repo is private, make sure you are authenticated and your token has the required permissions.
Invalid username or password.
```
"""
repo_id: str | None = None
repo_type: str | None = None
class GatedRepoError(RepositoryNotFoundError):
"""
@ -253,6 +323,12 @@ class RevisionNotFoundError(HfHubHTTPError):
Raised when trying to access a hf.co URL with a valid repository but an invalid
revision.
Attributes:
repo_id (`str` or `None`):
The repo id, if it could be determined from the request URL.
repo_type (`str` or `None`):
The repo type ("model", "dataset", or "space"), if it could be determined from the request URL.
Example:
```py
@ -265,6 +341,9 @@ class RevisionNotFoundError(HfHubHTTPError):
```
"""
repo_id: str | None = None
repo_type: str | None = None
# ENTRY ERRORS
class EntryNotFoundError(Exception):
@ -290,6 +369,12 @@ class RemoteEntryNotFoundError(HfHubHTTPError, EntryNotFoundError):
Raised when trying to access a hf.co URL with a valid repository and revision
but an invalid filename.
Attributes:
repo_id (`str` or `None`):
The repo id, if it could be determined from the request URL.
repo_type (`str` or `None`):
The repo type ("model", "dataset", or "space"), if it could be determined from the request URL.
Example:
```py
@ -302,6 +387,9 @@ class RemoteEntryNotFoundError(HfHubHTTPError, EntryNotFoundError):
```
"""
repo_id: str | None = None
repo_type: str | None = None
class LocalEntryNotFoundError(FileNotFoundError, EntryNotFoundError):
"""
@ -388,17 +476,27 @@ class StrictDataclassClassValidationError(StrictDataclassError):
# XET ERRORS
class XetError(Exception):
"""Base exception for errors related to Xet Storage."""
class XetAuthorizationError(XetError):
"""Exception thrown when the user does not have the right authorization to use Xet Storage."""
class XetRefreshTokenError(XetError):
"""Exception thrown when the refresh token is invalid."""
class XetDownloadError(Exception):
"""Exception thrown when the download from Xet Storage fails."""
# LFS ERRORS
class FileDuplicationError(Exception):
"""Raised when duplicating files across repos fails."""
# CLI ERRORS
class CLIError(Exception):
"""CLI error with clean message (no traceback by default)."""
class ConfirmationError(CLIError):
"""Raised when a confirmation prompt is declined (non-interactive mode)."""
class CLIExtensionInstallError(CLIError):
"""Error during CLI extension installation."""