-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: error resolution flow control without exceptions (#1095)
* Allowing flowcontrol with out exceptions So far we used exception to handle our flowcontrol, but Exceptions are costly. In the end we enriched our evaluation Details with errorCode and errorMessage. This can be also handled by the providers if desired, to reduce the execution footprint in errornous cases, which do not have to be exceptions. Eg FlagNotFound - it might be the case, but in performance critical environments, an exception rather than a normal return, can cause overhead and can be already too costly. Signed-off-by: Simon Schrottner <[email protected]> * fix: adding reason, and removing stacktraces from errors Signed-off-by: Simon Schrottner <[email protected]> * Update src/main/java/dev/openfeature/sdk/exceptions/TypeMismatchError.java Co-authored-by: Justin Abrahms <[email protected]> Signed-off-by: Simon Schrottner <[email protected]> --------- Signed-off-by: Simon Schrottner <[email protected]> Co-authored-by: Justin Abrahms <[email protected]>
- Loading branch information
1 parent
29901b8
commit 6fc0b90
Showing
7 changed files
with
110 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/main/java/dev/openfeature/sdk/exceptions/OpenFeatureErrorWithoutStacktrace.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package dev.openfeature.sdk.exceptions; | ||
|
||
import lombok.experimental.StandardException; | ||
|
||
@SuppressWarnings("checkstyle:MissingJavadocType") | ||
@StandardException | ||
public abstract class OpenFeatureErrorWithoutStacktrace extends OpenFeatureError { | ||
private static final long serialVersionUID = 1L; | ||
|
||
@Override | ||
public synchronized Throwable fillInStackTrace() { | ||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/test/java/dev/openfeature/sdk/AlwaysBrokenWithDetailsProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package dev.openfeature.sdk; | ||
|
||
import dev.openfeature.sdk.exceptions.FlagNotFoundError; | ||
|
||
public class AlwaysBrokenWithDetailsProvider implements FeatureProvider { | ||
|
||
@Override | ||
public Metadata getMetadata() { | ||
return () -> { | ||
throw new FlagNotFoundError(TestConstants.BROKEN_MESSAGE); | ||
}; | ||
} | ||
|
||
@Override | ||
public ProviderEvaluation<Boolean> getBooleanEvaluation(String key, Boolean defaultValue, EvaluationContext ctx) { | ||
return ProviderEvaluation.<Boolean>builder() | ||
.errorMessage(TestConstants.BROKEN_MESSAGE) | ||
.errorCode(ErrorCode.FLAG_NOT_FOUND) | ||
.build(); | ||
} | ||
|
||
@Override | ||
public ProviderEvaluation<String> getStringEvaluation(String key, String defaultValue, EvaluationContext ctx) { | ||
return ProviderEvaluation.<String>builder() | ||
.errorMessage(TestConstants.BROKEN_MESSAGE) | ||
.errorCode(ErrorCode.FLAG_NOT_FOUND) | ||
.build(); | ||
} | ||
|
||
@Override | ||
public ProviderEvaluation<Integer> getIntegerEvaluation(String key, Integer defaultValue, EvaluationContext ctx) { | ||
return ProviderEvaluation.<Integer>builder() | ||
.errorMessage(TestConstants.BROKEN_MESSAGE) | ||
.errorCode(ErrorCode.FLAG_NOT_FOUND) | ||
.build(); | ||
} | ||
|
||
@Override | ||
public ProviderEvaluation<Double> getDoubleEvaluation(String key, Double defaultValue, EvaluationContext ctx) { | ||
return ProviderEvaluation.<Double>builder() | ||
.errorMessage(TestConstants.BROKEN_MESSAGE) | ||
.errorCode(ErrorCode.FLAG_NOT_FOUND) | ||
.build(); | ||
} | ||
|
||
@Override | ||
public ProviderEvaluation<Value> getObjectEvaluation(String key, Value defaultValue, EvaluationContext invocationContext) { | ||
return ProviderEvaluation.<Value>builder() | ||
.errorMessage(TestConstants.BROKEN_MESSAGE) | ||
.errorCode(ErrorCode.FLAG_NOT_FOUND) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters