[docs]classBentoMLException(Exception):""" Base class for all BentoML's errors. Each custom exception should be derived from this class. """error_code=HTTPStatus.INTERNAL_SERVER_ERRORerror_mapping:dict[HTTPStatus,type[BentoMLException]]={}def__init_subclass__(cls)->None:if"error_code"incls.__dict__:cls.error_mapping.setdefault(cls.error_code,cls)def__init__(self,message:str,*,error_code:HTTPStatus|None=None):self.message=messageiferror_codeisnotNone:self.error_code=error_codesuper().__init__(message)
classStateException(Exception):""" Raised when the state of an object is not valid. """error_code=HTTPStatus.BAD_REQUEST
[docs]classRemoteException(BentoMLException):""" A special exception that is used to wrap the exception from remote server """def__init__(self,message:str,payload:BentoMLException|None=None):self.payload=payloadsuper().__init__(message)
[docs]classInvalidArgument(BentoMLException):""" Raised when BentoML received unexpected/invalid arguments from CLI arguments, HTTP Request, or python API function parameters. """error_code=HTTPStatus.BAD_REQUEST
[docs]classInternalServerError(BentoMLException):""" Raised when BentoML received valid arguments from CLI arguments, HTTP Request, or python API function parameters, but got internal issues while processing. * Note to BentoML developers: raise this exception only when exceptions happend in the users' code (runner or service) and want to surface it to the user. """
classAPIDeprecated(BentoMLException):""" Raised when trying to use deprecated APIs of BentoML """
[docs]classBadInput(InvalidArgument):"""Raised when API server receiving bad input request"""error_code=HTTPStatus.BAD_REQUEST
[docs]classNotFound(BentoMLException):""" Raised when specified resource or name not found """error_code=HTTPStatus.NOT_FOUND
classUnprocessableEntity(BentoMLException):""" Raised when API server receiving unprocessable entity request """error_code=HTTPStatus.UNPROCESSABLE_ENTITY
[docs]classServiceUnavailable(BentoMLException):""" Raised when incoming requests exceeds the capacity of a server """error_code=HTTPStatus.SERVICE_UNAVAILABLE
[docs]classBentoMLConfigException(BentoMLException):"""Raised when BentoML is mis-configured or when required configuration is missing"""
[docs]classMissingDependencyException(BentoMLException):""" Raised when BentoML component failed to load required dependencies. Some BentoML components have optional dependencies that can be installed as extensions. For example, when using the :class:`~bentoml._internal.io_descriptors.json.JSON` IODescriptor, ``pydantic`` is considered as an optional feature if users want to use it to validate. BentoML will still work without ``pydantic`` installed. """
classCLIException(BentoMLException):"""Raised when CLI encounters an issue"""classCloudRESTApiClientError(BentoMLException):"""Raised when communicating with Yatai or BentoCloud server."""pass
[docs]classImportServiceError(BentoMLException):"""Raised when BentoML failed to import the user's service file."""pass
classUnservableException(StateException):"""Raised when a service is not servable."""passclassServerStateException(StateException):"""Raised when a server API requiring the BentoML server to be running is executed when the server is not running."""pass