Skip to content

Commit 0985315

Browse files
fix(flagd): implement error code step and general error (#1519)
Signed-off-by: Konvalinka <[email protected]> Co-authored-by: lea konvalinka <[email protected]>
1 parent 7832391 commit 0985315

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

providers/flagd/src/main/java/dev/openfeature/contrib/providers/flagd/resolver/process/InProcessResolver.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import dev.openfeature.sdk.ProviderEvent;
2323
import dev.openfeature.sdk.Reason;
2424
import dev.openfeature.sdk.Value;
25+
import dev.openfeature.sdk.exceptions.GeneralError;
2526
import dev.openfeature.sdk.exceptions.ParseError;
2627
import dev.openfeature.sdk.exceptions.TypeMismatchError;
2728
import java.util.Map;
@@ -205,7 +206,7 @@ private <T> ProviderEvaluation<T> resolve(Class<T> type, String key, EvaluationC
205206
if (value == null) {
206207
String message = String.format("variant %s not found in flag with key %s", resolvedVariant, key);
207208
log.debug(message);
208-
throw new TypeMismatchError(message);
209+
throw new GeneralError(message);
209210
}
210211
if (value instanceof Integer && type == Double.class) {
211212
// if this is an integer and we are trying to resolve a double, convert

providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/RunInProcessTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "dev.openfeature.contrib.providers.flagd.e2e.steps")
3030
@ConfigurationParameter(key = OBJECT_FACTORY_PROPERTY_NAME, value = "io.cucumber.picocontainer.PicoFactory")
3131
@IncludeTags("in-process")
32-
@ExcludeTags({"unixsocket", "targetURI"})
32+
@ExcludeTags({"unixsocket", "targetURI", "no-default"})
3333
@Testcontainers
3434
@Isolated
3535
public class RunInProcessTest {

providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/steps/FlagSteps.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static org.assertj.core.api.Assertions.assertThat;
44

55
import dev.openfeature.contrib.providers.flagd.e2e.State;
6+
import dev.openfeature.sdk.ErrorCode;
67
import dev.openfeature.sdk.FlagEvaluationDetails;
78
import dev.openfeature.sdk.ImmutableMetadata;
89
import dev.openfeature.sdk.Value;
@@ -77,6 +78,15 @@ public void the_variant_should_be(String variant) {
7778
assertThat(state.evaluation.getVariant()).isEqualTo(variant);
7879
}
7980

81+
@Then("the error-code should be {string}")
82+
public void the_error_code_should_be(String errorCode) {
83+
if (errorCode.isEmpty()) {
84+
assertThat(state.evaluation.getErrorCode()).isNull();
85+
} else {
86+
assertThat(state.evaluation.getErrorCode()).isEqualTo(ErrorCode.valueOf(errorCode));
87+
}
88+
}
89+
8090
@Then("the flag should be part of the event payload")
8191
public void the_flag_was_modified() {
8292
Event event = state.lastEvent.orElseThrow(AssertionError::new);

providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/resolver/process/InProcessResolverTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import dev.openfeature.sdk.ProviderEvaluation;
3636
import dev.openfeature.sdk.Reason;
3737
import dev.openfeature.sdk.Value;
38+
import dev.openfeature.sdk.exceptions.GeneralError;
3839
import dev.openfeature.sdk.exceptions.ParseError;
3940
import dev.openfeature.sdk.exceptions.TypeMismatchError;
4041
import java.lang.reflect.Field;
@@ -279,7 +280,7 @@ public void variantMismatchFlag() throws Exception {
279280
getInProcessResolverWith(new MockStorage(flagMap), (connectionEvent) -> {});
280281

281282
// when/then
282-
assertThrows(TypeMismatchError.class, () -> {
283+
assertThrows(GeneralError.class, () -> {
283284
inProcessResolver.booleanEvaluation("mismatchFlag", false, new ImmutableContext());
284285
});
285286
}
@@ -288,14 +289,14 @@ public void variantMismatchFlag() throws Exception {
288289
public void typeMismatchEvaluation() throws Exception {
289290
// given
290291
final Map<String, FeatureFlag> flagMap = new HashMap<>();
291-
flagMap.put("stringFlag", BOOLEAN_FLAG);
292+
flagMap.put("booleanFlag", BOOLEAN_FLAG);
292293

293294
InProcessResolver inProcessResolver =
294295
getInProcessResolverWith(new MockStorage(flagMap), (connectionEvent) -> {});
295296

296297
// when/then
297298
assertThrows(TypeMismatchError.class, () -> {
298-
inProcessResolver.stringEvaluation("stringFlag", "false", new ImmutableContext());
299+
inProcessResolver.stringEvaluation("booleanFlag", "false", new ImmutableContext());
299300
});
300301
}
301302

0 commit comments

Comments
 (0)