From e4d7afdce8fc2596d1a27f2d85f259f2fa35bafa Mon Sep 17 00:00:00 2001 From: Tomas Pereira de Vasconcelos Date: Wed, 3 Aug 2022 16:21:18 +0200 Subject: [PATCH] fix: More explicit error messages (#2708) Add more explicit error messages to validation checks in repo_config.py (for better pydantic error messages) Signed-off-by: Tomas Pereira de Vasconcelos --- sdk/python/feast/errors.py | 7 +++++++ sdk/python/feast/repo_config.py | 16 ++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/sdk/python/feast/errors.py b/sdk/python/feast/errors.py index 980dfd470f..0279d125da 100644 --- a/sdk/python/feast/errors.py +++ b/sdk/python/feast/errors.py @@ -197,6 +197,13 @@ def __init__( ) +class FeastOfflineStoreInvalidName(Exception): + def __init__(self, offline_store_class_name: str): + super().__init__( + f"Offline Store Class '{offline_store_class_name}' should end with the string `OfflineStore`.'" + ) + + class FeastOnlineStoreInvalidName(Exception): def __init__(self, online_store_class_name: str): super().__init__( diff --git a/sdk/python/feast/repo_config.py b/sdk/python/feast/repo_config.py index 587907b284..86cff7c8b0 100644 --- a/sdk/python/feast/repo_config.py +++ b/sdk/python/feast/repo_config.py @@ -21,6 +21,8 @@ from feast.errors import ( FeastFeatureServerTypeInvalidError, FeastFeatureServerTypeSetError, + FeastOfflineStoreInvalidName, + FeastOnlineStoreInvalidName, FeastProviderNotSetError, ) from feast.importer import import_class @@ -278,7 +280,8 @@ def _validate_online_store_config(cls, values): return values # Make sure that the provider configuration is set. We need it to set the defaults - assert "provider" in values + if "provider" not in values: + raise FeastProviderNotSetError() # Set the default type # This is only direct reference to a provider or online store that we should have @@ -315,7 +318,8 @@ def _validate_offline_store_config(cls, values): return values # Make sure that the provider configuration is set. We need it to set the defaults - assert "provider" in values + if "provider" not in values: + raise FeastProviderNotSetError() # Set the default type if "type" not in values["offline_store"]: @@ -455,8 +459,8 @@ def get_batch_engine_config_from_type(batch_engine_type: str): def get_online_config_from_type(online_store_type: str): if online_store_type in ONLINE_STORE_CLASS_FOR_TYPE: online_store_type = ONLINE_STORE_CLASS_FOR_TYPE[online_store_type] - else: - assert online_store_type.endswith("OnlineStore") + elif not online_store_type.endswith("OnlineStore"): + raise FeastOnlineStoreInvalidName(online_store_type) module_name, online_store_class_type = online_store_type.rsplit(".", 1) config_class_name = f"{online_store_class_type}Config" @@ -466,8 +470,8 @@ def get_online_config_from_type(online_store_type: str): def get_offline_config_from_type(offline_store_type: str): if offline_store_type in OFFLINE_STORE_CLASS_FOR_TYPE: offline_store_type = OFFLINE_STORE_CLASS_FOR_TYPE[offline_store_type] - else: - assert offline_store_type.endswith("OfflineStore") + elif not offline_store_type.endswith("OfflineStore"): + raise FeastOfflineStoreInvalidName(offline_store_type) module_name, offline_store_class_type = offline_store_type.rsplit(".", 1) config_class_name = f"{offline_store_class_type}Config"