Skip to content

Commit bff8b6a

Browse files
committed
feat: use custom FeatureGatingError in feature gating helpers
1 parent c72bc30 commit bff8b6a

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

packages/google-api-core/google/api_core/_feature_gating_helpers.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
_FALSY_VALUES = ("n", "no", "f", "false", "off", "0")
2929

3030

31+
class FeatureGatingError(ValueError):
32+
"""Raised when feature gating resolution fails or is misconfigured."""
33+
pass
34+
35+
3136
def _strtobool(val: str) -> bool | None:
3237
"""Convert a string representation of truth to a boolean."""
3338
clean_val = val.lower().strip()
@@ -114,7 +119,7 @@ def resolve_feature_flags(
114119
if "EXPERIMENTAL" in env_var:
115120
# Fail Fast if provider present but experimental environment variable is not enabled
116121
if env_var_setting is not True and has_provider:
117-
raise ValueError(
122+
raise FeatureGatingError(
118123
f"Experimental feature requires {env_var} to be set to 'true' to use programmatic providers."
119124
)
120125

packages/google-api-core/tests/unit/test_feature_gating_helpers.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import pytest
1616
from google.api_core import _feature_gating_helpers
1717
from google.api_core._feature_gating_helpers import (
18+
FeatureGatingError,
1819
_get_env_bool,
1920
_strtobool,
2021
)
@@ -99,8 +100,8 @@ def test_resolve_feature_flags_exp_blocked_with_provider_fails_fast(
99100
configuration = {"tracer_provider": object()}
100101

101102
# Action & Assertion
102-
with pytest.raises(ValueError, match="Experimental feature"):
103-
feature_gating_helpers.resolve_feature_flags(
103+
with pytest.raises(FeatureGatingError, match="Experimental feature"):
104+
_feature_gating_helpers.resolve_feature_flags(
104105
env_var="GOOGLE_SDK_EXPERIMENTAL_PYTHON_TRACING_ENABLED",
105106
feature_key="tracer_provider",
106107
configuration=configuration,

0 commit comments

Comments
 (0)