Add exceptions

This commit is contained in:
Andras Schmelczer 2022-07-04 08:47:52 +02:00
parent 92a0b0ba55
commit bb1077d45f
5 changed files with 12 additions and 4 deletions

View file

@ -1,5 +1,10 @@
from .context import configure from .context import configure
from .deploy import GreatAI from .deploy import GreatAI
from .exceptions import (
ArgumentValidationError,
MissingArgumentError,
WrongDecoratorOrderError,
)
from .models import save_model, use_model from .models import save_model, use_model
from .output_models import ( from .output_models import (
ClassificationOutput, ClassificationOutput,

View file

@ -1,2 +1,3 @@
from .argument_validation_error import ArgumentValidationError from .argument_validation_error import ArgumentValidationError
from .missing_argument_error import MissingArgumentError from .missing_argument_error import MissingArgumentError
from .wrong_decorator_order_error import WrongDecoratorOrderError

View file

@ -0,0 +1,2 @@
class WrongDecoratorOrderError(Exception):
pass

View file

@ -1,6 +1,6 @@
from typing import Any, Callable from typing import Any, Callable
from ..context import get_context from ..exceptions import WrongDecoratorOrderError
from .get_function_metadata_store import get_function_metadata_store from .get_function_metadata_store import get_function_metadata_store
@ -11,5 +11,4 @@ def assert_function_is_not_finalised(func: Callable[..., Any]) -> None:
) )
if get_function_metadata_store(func).is_finalised: if get_function_metadata_store(func).is_finalised:
get_context().logger.error(error_message) raise WrongDecoratorOrderError(error_message)
exit(-1)

View file

@ -8,13 +8,14 @@ from ..helper import get_arguments, get_function_metadata_store
from ..helper.assert_function_is_not_finalised import assert_function_is_not_finalised from ..helper.assert_function_is_not_finalised import assert_function_is_not_finalised
from ..tracing.tracing_context import TracingContext from ..tracing.tracing_context import TracingContext
T = TypeVar("T")
F = TypeVar("F", bound=Callable[..., Any]) F = TypeVar("F", bound=Callable[..., Any])
def parameter( def parameter(
parameter_name: str, parameter_name: str,
*, *,
validator: Callable[[Any], bool] = lambda _: True, validator: Callable[[T], bool] = lambda _: True,
disable_logging: bool = False, disable_logging: bool = False,
) -> Callable[[F], F]: ) -> Callable[[F], F]:
def decorator(func: F) -> F: def decorator(func: F) -> F: