# ruff: noqa: D101, D102
from .exceptions import ErsiliaError
[docs]
class ApiErsiliaError(ErsiliaError):
def __init__(self):
self.message = "Error occurred while running api command"
self.hints = ""
ErsiliaError.__init__(self, self.message, self.hints)
[docs]
class ApiSpecifiedOutputError(ErsiliaError):
def __init__(self):
self.message = "Specified output is not correct"
self.hints = "If you don't specify an output, an interable will be created. If you specify a file extension (.json, .tsv, .csv or .h5), a file will be created. Other valid strings include 'dict', 'numpy', 'pandas' and 'json'"
ErsiliaError.__init__(self, self.message, self.hints)
# Errors raised by the Python API (ersilia.api). Messages match the CLI's.
[docs]
class InvalidOptionError(ErsiliaError):
def __init__(self, message, hints=""):
self.message = message
self.hints = hints
ErsiliaError.__init__(self, self.message, self.hints)
[docs]
class ModelNotServedError(ErsiliaError):
def __init__(self, model_id, stopped=False):
self.model_id = model_id
if stopped:
self.message = (
"Model {0} is no longer running (its server stopped).".format(model_id)
)
self.hints = "Call serve() again."
else:
self.message = "Model {0} is not being served.".format(model_id)
self.hints = "Call serve() first."
ErsiliaError.__init__(self, self.message, self.hints)
[docs]
class SessionBusyError(ErsiliaError):
def __init__(self, served_model_id, model_id):
self.served_model_id = served_model_id
self.message = "Model {0} is already being served in this session.".format(
served_model_id
)
self.hints = (
"Close it first, e.g. Model('{0}').close(), then serve {1}.".format(
served_model_id, model_id
)
)
ErsiliaError.__init__(self, self.message, self.hints)
[docs]
class ModelFetchError(ErsiliaError):
def __init__(self, model_id, reason):
self.model_id = model_id
self.reason = reason
self.message = "Model {0} could not be fetched.".format(model_id)
self.hints = reason or ""
ErsiliaError.__init__(self, self.message, self.hints)
[docs]
class ModelServeError(ErsiliaError):
def __init__(self, model_id):
self.model_id = model_id
self.message = "Model {0} could not be started.".format(model_id)
self.hints = "Try again with verbose=True to see the details."
ErsiliaError.__init__(self, self.message, self.hints)
[docs]
class ModelNotDeletableError(ErsiliaError):
def __init__(self, model_id, reason):
self.model_id = model_id
self.message = "Model {0} cannot be deleted.".format(model_id)
self.hints = reason or ""
ErsiliaError.__init__(self, self.message, self.hints)
[docs]
class EmptyRunOutputError(ErsiliaError):
def __init__(self, model_id):
self.model_id = model_id
self.message = "Model {0} produced no output.".format(model_id)
self.hints = "Check that the input suits this model."
ErsiliaError.__init__(self, self.message, self.hints)