Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: flow instead of exceptions in resolver #942

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
import dev.openfeature.contrib.providers.flagd.resolver.process.storage.connector.grpc.GrpcStreamConnector;
import dev.openfeature.contrib.providers.flagd.resolver.process.targeting.Operator;
import dev.openfeature.contrib.providers.flagd.resolver.process.targeting.TargetingRuleException;
import dev.openfeature.sdk.ErrorCode;
import dev.openfeature.sdk.EvaluationContext;
import dev.openfeature.sdk.ImmutableMetadata;
import dev.openfeature.sdk.ProviderEvaluation;
import dev.openfeature.sdk.ProviderState;
import dev.openfeature.sdk.Reason;
import dev.openfeature.sdk.Value;
import dev.openfeature.sdk.exceptions.FlagNotFoundError;
import dev.openfeature.sdk.exceptions.ParseError;
import dev.openfeature.sdk.exceptions.TypeMismatchError;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -164,12 +164,18 @@ private <T> ProviderEvaluation<T> resolve(Class<T> type, String key, EvaluationC

// missing flag
if (flag == null) {
throw new FlagNotFoundError("flag: " + key + " not found");
return ProviderEvaluation.<T>builder()
.errorMessage("flag: " + key + " not found")
.errorCode(ErrorCode.FLAG_NOT_FOUND)
.build();
}

// state check
if ("DISABLED".equals(flag.getState())) {
throw new FlagNotFoundError("flag: " + key + " is disabled");
return ProviderEvaluation.<T>builder()
.errorMessage("flag: " + key + " is disabled")
.errorCode(ErrorCode.FLAG_NOT_FOUND)
.build();
}

final String resolvedVariant;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import dev.openfeature.contrib.providers.flagd.resolver.process.storage.StorageStateChange;
import dev.openfeature.contrib.providers.flagd.resolver.process.storage.connector.file.FileConnector;
import dev.openfeature.contrib.providers.flagd.resolver.process.storage.connector.grpc.GrpcStreamConnector;
import dev.openfeature.sdk.ErrorCode;
import dev.openfeature.sdk.ImmutableContext;
import dev.openfeature.sdk.ImmutableMetadata;
import dev.openfeature.sdk.MutableContext;
Expand Down Expand Up @@ -239,10 +240,8 @@ public void missingFlag() throws Exception {
});

// when/then
assertThrows(FlagNotFoundError.class, () -> {
inProcessResolver.booleanEvaluation("missingFlag", false, new ImmutableContext());

});
ProviderEvaluation<Boolean> missingFlag = inProcessResolver.booleanEvaluation("missingFlag", false, new ImmutableContext());
assertEquals(ErrorCode.FLAG_NOT_FOUND, missingFlag.getErrorCode());
}

@Test
Expand All @@ -256,9 +255,8 @@ public void disabledFlag() throws Exception {
});

// when/then
assertThrows(FlagNotFoundError.class, () -> {
inProcessResolver.booleanEvaluation("disabledFlag", false, new ImmutableContext());
});
ProviderEvaluation<Boolean> disabledFlag = inProcessResolver.booleanEvaluation("disabledFlag", false, new ImmutableContext());
assertEquals(ErrorCode.FLAG_NOT_FOUND, disabledFlag.getErrorCode());
}

@Test
Expand Down