-
Notifications
You must be signed in to change notification settings - Fork 40
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!: errorCode as enum, reason as string #80
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package dev.openfeature.javasdk; | ||
|
||
public enum ErrorCode { | ||
PROVIDER_NOT_READY, FLAG_NOT_FOUND, PARSE_ERROR, TYPE_MISMATCH, GENERAL | ||
PROVIDER_NOT_READY, FLAG_NOT_FOUND, PARSE_ERROR, TYPE_MISMATCH, TARGETING_KEY_MISSING, INVALID_CONTEXT, GENERAL | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Spec change. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ public ProviderEvaluation<Boolean> getBooleanEvaluation(String key, Boolean defa | |
return ProviderEvaluation.<Boolean>builder() | ||
.value(defaultValue) | ||
.variant(PASSED_IN_DEFAULT) | ||
.reason(Reason.DEFAULT) | ||
.reason(Reason.DEFAULT.toString()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's still good to have an enum of default reasons. We just convert them to strings where applicable. We can instead use string constants... anyone have opinions on this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes this a good idea to keep the enum 👍 |
||
.build(); | ||
} | ||
|
||
|
@@ -34,7 +34,7 @@ public ProviderEvaluation<String> getStringEvaluation(String key, String default | |
return ProviderEvaluation.<String>builder() | ||
.value(defaultValue) | ||
.variant(PASSED_IN_DEFAULT) | ||
.reason(Reason.DEFAULT) | ||
.reason(Reason.DEFAULT.toString()) | ||
.build(); | ||
} | ||
|
||
|
@@ -43,7 +43,7 @@ public ProviderEvaluation<Integer> getIntegerEvaluation(String key, Integer defa | |
return ProviderEvaluation.<Integer>builder() | ||
.value(defaultValue) | ||
.variant(PASSED_IN_DEFAULT) | ||
.reason(Reason.DEFAULT) | ||
.reason(Reason.DEFAULT.toString()) | ||
.build(); | ||
} | ||
|
||
|
@@ -52,7 +52,7 @@ public ProviderEvaluation<Double> getDoubleEvaluation(String key, Double default | |
return ProviderEvaluation.<Double>builder() | ||
.value(defaultValue) | ||
.variant(PASSED_IN_DEFAULT) | ||
.reason(Reason.DEFAULT) | ||
.reason(Reason.DEFAULT.toString()) | ||
.build(); | ||
} | ||
|
||
|
@@ -62,7 +62,7 @@ public ProviderEvaluation<Value> getObjectEvaluation(String key, Value defaultVa | |
return ProviderEvaluation.<Value>builder() | ||
.value(defaultValue) | ||
.variant(PASSED_IN_DEFAULT) | ||
.reason(Reason.DEFAULT) | ||
.reason(Reason.DEFAULT.toString()) | ||
.build(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
import java.util.Map; | ||
|
||
import dev.openfeature.javasdk.exceptions.GeneralError; | ||
import dev.openfeature.javasdk.exceptions.OpenFeatureError; | ||
import dev.openfeature.javasdk.internal.ObjectUtils; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
@@ -94,9 +95,14 @@ private <T> FlagEvaluationDetails<T> evaluateFlag(FlagValueType type, String key | |
if (details == null) { | ||
details = FlagEvaluationDetails.<T>builder().build(); | ||
} | ||
if (e instanceof OpenFeatureError) { | ||
details.setErrorCode(((OpenFeatureError)e).getErrorCode()); | ||
} else { | ||
details.setErrorCode(ErrorCode.GENERAL); | ||
} | ||
details.setErrorMessage(e.getMessage()); | ||
details.setValue(defaultValue); | ||
details.setReason(Reason.ERROR); | ||
details.setErrorCode(e.getMessage()); | ||
details.setReason(Reason.ERROR.toString()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we consider whether a provider might want to different reason to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The spec says that reason must indicate an error in error cases (1.4.8). This is in the I suppose the provider could provide a more specific error reason, but I think additional information can be better conveyed by the |
||
hookSupport.errorHooks(type, hookCtx, e, mergedHooks, hints); | ||
} finally { | ||
hookSupport.afterAllHooks(type, hookCtx, mergedHooks, hints); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
public class ProviderEvaluation<T> implements BaseEvaluation<T> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be useful to have an overload for setting the reason based on a Reason? I am not really sure how these lombok classes work, aside from magic. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm hesitant to add it b/c it's not something lombok can do for us. I'm lazy. |
||
T value; | ||
@Nullable String variant; | ||
Reason reason; | ||
@Nullable String errorCode; | ||
@Nullable private String reason; | ||
ErrorCode errorCode; | ||
@Nullable private String errorMessage; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,5 +7,5 @@ | |
@StandardException | ||
public class FlagNotFoundError extends OpenFeatureError { | ||
private static final long serialVersionUID = 1L; | ||
@Getter private final ErrorCode errorCode = ErrorCode.GENERAL; | ||
@Getter private final ErrorCode errorCode = ErrorCode.FLAG_NOT_FOUND; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this was an existing bug, unless I'm missing something. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package dev.openfeature.javasdk.exceptions; | ||
|
||
import dev.openfeature.javasdk.ErrorCode; | ||
import lombok.Getter; | ||
import lombok.experimental.StandardException; | ||
|
||
@StandardException | ||
public class InvalidContextError extends OpenFeatureError { | ||
private static final long serialVersionUID = 1L; | ||
|
||
@Getter private final ErrorCode errorCode = ErrorCode.INVALID_CONTEXT; | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package dev.openfeature.javasdk.exceptions; | ||
|
||
import dev.openfeature.javasdk.ErrorCode; | ||
import lombok.Getter; | ||
import lombok.experimental.StandardException; | ||
|
||
@StandardException | ||
public class TargetingKeyMissingError extends OpenFeatureError { | ||
private static final long serialVersionUID = 1L; | ||
|
||
@Getter private final ErrorCode errorCode = ErrorCode.TARGETING_KEY_MISSING; | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,41 @@ | ||
package dev.openfeature.javasdk; | ||
|
||
import dev.openfeature.javasdk.exceptions.FlagNotFoundError; | ||
|
||
public class AlwaysBrokenProvider implements FeatureProvider { | ||
|
||
@Override | ||
public Metadata getMetadata() { | ||
return new Metadata() { | ||
@Override | ||
public String getName() { | ||
throw new NotImplementedException("BORK"); | ||
throw new FlagNotFoundError(TestConstants.BROKEN_MESSAGE); | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public ProviderEvaluation<Boolean> getBooleanEvaluation(String key, Boolean defaultValue, EvaluationContext ctx) { | ||
throw new NotImplementedException("BORK"); | ||
throw new FlagNotFoundError(TestConstants.BROKEN_MESSAGE); | ||
} | ||
|
||
@Override | ||
public ProviderEvaluation<String> getStringEvaluation(String key, String defaultValue, EvaluationContext ctx) { | ||
throw new NotImplementedException("BORK"); | ||
throw new FlagNotFoundError(TestConstants.BROKEN_MESSAGE); | ||
} | ||
|
||
@Override | ||
public ProviderEvaluation<Integer> getIntegerEvaluation(String key, Integer defaultValue, EvaluationContext ctx) { | ||
throw new NotImplementedException("BORK"); | ||
throw new FlagNotFoundError(TestConstants.BROKEN_MESSAGE); | ||
} | ||
|
||
@Override | ||
public ProviderEvaluation<Double> getDoubleEvaluation(String key, Double defaultValue, EvaluationContext ctx) { | ||
throw new NotImplementedException("BORK"); | ||
throw new FlagNotFoundError(TestConstants.BROKEN_MESSAGE); | ||
} | ||
|
||
@Override | ||
public ProviderEvaluation<Value> getObjectEvaluation(String key, Value defaultValue, EvaluationContext invocationContext) { | ||
throw new NotImplementedException("BORK"); | ||
throw new FlagNotFoundError(TestConstants.BROKEN_MESSAGE); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package dev.openfeature.javasdk; | ||
|
||
public class TestConstants { | ||
public static final String BROKEN_MESSAGE = "This is borked."; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing the
integration-test
profile disables the integration test suite as discussed in the description.