Skip to content

Commit e0ab7a1

Browse files
committed
refactor: rename ConfigurationError to ConfigurationStoreError, impro catch
1 parent a55131f commit e0ab7a1

File tree

6 files changed

+21
-18
lines changed

6 files changed

+21
-18
lines changed

aws_lambda_powertools/utilities/feature_flags/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
"""
33
from .appconfig import AppConfigStore
44
from .base import StoreProvider
5-
from .exceptions import ConfigurationError
5+
from .exceptions import ConfigurationStoreError
66
from .feature_flags import FeatureFlags
77
from .schema import RuleAction, SchemaValidator
88

99
__all__ = [
10-
"ConfigurationError",
10+
"ConfigurationStoreError",
1111
"FeatureFlags",
1212
"RuleAction",
1313
"SchemaValidator",

aws_lambda_powertools/utilities/feature_flags/appconfig.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from ...shared import jmespath_utils
99
from .base import StoreProvider
10-
from .exceptions import ConfigurationError
10+
from .exceptions import ConfigurationStoreError
1111

1212
logger = logging.getLogger(__name__)
1313

@@ -59,7 +59,7 @@ def get_configuration(self) -> Dict[str, Any]:
5959
6060
Raises
6161
------
62-
ConfigurationError
62+
ConfigurationStoreError
6363
Any validation error or AppConfig error that can occur
6464
6565
Returns
@@ -82,4 +82,4 @@ def get_configuration(self) -> Dict[str, Any]:
8282

8383
return cast(dict, config)
8484
except (GetParameterError, TransformParameterError) as exc:
85-
raise ConfigurationError("Unable to get AWS AppConfig configuration file") from exc
85+
raise ConfigurationStoreError("Unable to get AWS AppConfig configuration file") from exc

aws_lambda_powertools/utilities/feature_flags/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def get_configuration(self) -> Dict[str, Any]:
99
1010
Raises
1111
------
12-
ConfigurationError
12+
ConfigurationStoreError
1313
Any error that can occur during schema fetch or JSON parse
1414
1515
Returns

aws_lambda_powertools/utilities/feature_flags/exceptions.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class ConfigurationError(Exception):
1+
class ConfigurationStoreError(Exception):
22
"""When a configuration store raises an exception on config retrieval or parsing"""
33

44

aws_lambda_powertools/utilities/feature_flags/feature_flags.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from . import schema
55
from .base import StoreProvider
6-
from .exceptions import ConfigurationError
6+
from .exceptions import ConfigurationStoreError
77

88
logger = logging.getLogger(__name__)
99

@@ -103,8 +103,8 @@ def get_configuration(self) -> Union[Dict[str, Dict], Dict]:
103103
104104
Raises
105105
------
106-
ConfigurationError
107-
Any validation error
106+
ConfigurationStoreError
107+
Any propagated error from store
108108
SchemaValidationError
109109
When schema doesn't conform with feature flag schema
110110
@@ -140,7 +140,10 @@ def get_configuration(self) -> Union[Dict[str, Dict], Dict]:
140140
"""
141141
# parse result conf as JSON, keep in cache for max age defined in store
142142
logger.debug(f"Fetching schema from registered store, store={self._store}")
143-
config = self._store.get_configuration()
143+
try:
144+
config = self._store.get_configuration()
145+
except Exception as err:
146+
raise ConfigurationStoreError("Unable to fetch schema from registered store") from err
144147

145148
validator = schema.SchemaValidator(schema=config)
146149
validator.validate()
@@ -183,7 +186,7 @@ def evaluate(self, *, name: str, context: Optional[Dict[str, Any]] = None, defau
183186

184187
try:
185188
features = self.get_configuration()
186-
except ConfigurationError as err:
189+
except ConfigurationStoreError as err:
187190
logger.debug(f"Failed to fetch feature flags from store, returning default provided, reason={err}")
188191
return default
189192

@@ -234,7 +237,7 @@ def get_enabled_features(self, *, context: Optional[Dict[str, Any]] = None) -> L
234237

235238
try:
236239
features: Dict[str, Any] = self.get_configuration()
237-
except ConfigurationError as err:
240+
except ConfigurationStoreError as err:
238241
logger.debug(f"Failed to fetch feature flags from store, returning empty list, reason={err}")
239242
return features_enabled
240243

tests/functional/feature_toggles/test_feature_toggles.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import pytest
44
from botocore.config import Config
55

6-
from aws_lambda_powertools.utilities.feature_flags import ConfigurationError, schema
6+
from aws_lambda_powertools.utilities.feature_flags import ConfigurationStoreError, schema
77
from aws_lambda_powertools.utilities.feature_flags.appconfig import AppConfigStore
88
from aws_lambda_powertools.utilities.feature_flags.feature_flags import FeatureFlags
99
from aws_lambda_powertools.utilities.feature_flags.schema import RuleAction
@@ -387,7 +387,7 @@ def test_multiple_features_only_some_enabled(mocker, config):
387387

388388

389389
def test_get_feature_toggle_handles_error(mocker, config):
390-
# GIVEN a schema fetch that raises a ConfigurationError
390+
# GIVEN a schema fetch that raises a ConfigurationStoreError
391391
schema_fetcher = init_fetcher_side_effect(mocker, config, GetParameterError())
392392
feature_flags = FeatureFlags(schema_fetcher)
393393

@@ -399,7 +399,7 @@ def test_get_feature_toggle_handles_error(mocker, config):
399399

400400

401401
def test_get_all_enabled_feature_toggles_handles_error(mocker, config):
402-
# GIVEN a schema fetch that raises a ConfigurationError
402+
# GIVEN a schema fetch that raises a ConfigurationStoreError
403403
schema_fetcher = init_fetcher_side_effect(mocker, config, GetParameterError())
404404
feature_flags = FeatureFlags(schema_fetcher)
405405

@@ -415,10 +415,10 @@ def test_app_config_get_parameter_err(mocker, config):
415415
app_conf_fetcher = init_fetcher_side_effect(mocker, config, GetParameterError())
416416

417417
# WHEN calling get_configuration
418-
with pytest.raises(ConfigurationError) as err:
418+
with pytest.raises(ConfigurationStoreError) as err:
419419
app_conf_fetcher.get_configuration()
420420

421-
# THEN raise ConfigurationError error
421+
# THEN raise ConfigurationStoreError error
422422
assert "AWS AppConfig configuration" in str(err.value)
423423

424424

0 commit comments

Comments
 (0)