Skip to content

Commit 4c8153c

Browse files
committed
updating config helper to have descriptive exception in strict mode
1 parent e307e2c commit 4c8153c

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

utils/config-utils/src/main/java/datadog/trace/config/inversion/ConfigHelper.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ private ConfigHelper() {}
1515

1616
/** Config Inversion strictness policy for enforcement of undocumented environment variables */
1717
public enum StrictnessPolicy {
18-
STRICT,
18+
STRICT_TEST,
1919
WARNING,
2020
TEST;
2121

@@ -142,8 +142,12 @@ public String getEnvironmentVariable(String name) {
142142
ConfigInversionMetricCollectorProvider.get().setUndocumentedEnvVarMetric(name);
143143
}
144144

145-
if (configInversionStrict == StrictnessPolicy.STRICT) {
146-
return null; // If strict mode is enabled, return null for unsupported configs
145+
if (configInversionStrict == StrictnessPolicy.STRICT_TEST) {
146+
throw new IllegalArgumentException(
147+
"Unsupported configuration: "
148+
+ name
149+
+ " is not in GeneratedSupportedConfigurations. "
150+
+ "Add it to metadata/supported-configurations.json or remove the usage.");
147151
}
148152
}
149153

utils/config-utils/src/test/java/datadog/trace/config/inversion/ConfigHelperTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ static void setUp() {
6262
testSupported, testAliases, testAliasMapping, new HashMap<>());
6363
ConfigHelper.get().setConfigurationSource(testSource);
6464
strictness = ConfigHelper.get().configInversionStrictFlag();
65-
ConfigHelper.get().setConfigInversionStrict(ConfigHelper.StrictnessPolicy.STRICT);
65+
ConfigHelper.get().setConfigInversionStrict(ConfigHelper.StrictnessPolicy.STRICT_TEST);
6666
}
6767

6868
@AfterAll
@@ -177,7 +177,7 @@ void testUnsupportedEnvWarningNotInTestMode() {
177177
assertEquals("banana", ConfigHelper.env("DD_FAKE_VAR"));
178178

179179
// Cleanup
180-
ConfigHelper.get().setConfigInversionStrict(ConfigHelper.StrictnessPolicy.STRICT);
180+
ConfigHelper.get().setConfigInversionStrict(ConfigHelper.StrictnessPolicy.STRICT_TEST);
181181
}
182182

183183
@Test

0 commit comments

Comments
 (0)