Skip to content

Commit

Permalink
give a specific exception for common error
Browse files Browse the repository at this point in the history
  • Loading branch information
severo committed Aug 22, 2024
1 parent 04641e8 commit 6fa0e8a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
8 changes: 8 additions & 0 deletions libs/libcommon/src/libcommon/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def as_response(self) -> ErrorResponse:
"ExternalServerError",
"FeaturesError",
"FeaturesResponseEmptyError",
"FileFormatMismatchBetweenSplits",
"FileSystemError",
"HfHubError",
"InfoError",
Expand Down Expand Up @@ -331,6 +332,13 @@ def __init__(self, message: str, cause: Optional[BaseException] = None):
super().__init__(message, HTTPStatus.INTERNAL_SERVER_ERROR, "FeaturesResponseEmptyError", cause, True)


class FileFormatMismatchBetweenSplits(CacheableError):
"""Couldn't infer the same data file format for all splits."""

def __init__(self, message: str, cause: Optional[BaseException] = None):
super().__init__(message, HTTPStatus.INTERNAL_SERVER_ERROR, "FileFormatMismatchBetweenSplits", cause, False)


class FileSystemError(CacheableError):
"""An error happen reading from File System."""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
DatasetWithScriptNotSupportedError,
DatasetWithTooManyConfigsError,
EmptyDatasetError,
FileFormatMismatchBetweenSplits,
)

from worker.dtos import CompleteJobResult, ConfigNameItem, DatasetConfigNamesResponse
Expand Down Expand Up @@ -114,6 +115,8 @@ def compute_config_names_response(
except ValueError as err:
if "trust_remote_code" in str(err):
raise DatasetWithScriptNotSupportedError from err
if "Couldn't infer the same data file format for all splits" in str(err):
raise FileFormatMismatchBetweenSplits() from err
raise ConfigNamesError("Cannot get the config names for the dataset.", cause=err) from err
except ImportError as err:
# this should only happen if the dataset is in the allow list, which should soon disappear
Expand Down

0 comments on commit 6fa0e8a

Please sign in to comment.