Skip to content

Commit d523c6b

Browse files
committed
fix: adding reason, and removing stacktraces from errors
Signed-off-by: Simon Schrottner <[email protected]>
1 parent 7276acb commit d523c6b

File tree

6 files changed

+27
-10
lines changed

6 files changed

+27
-10
lines changed

src/main/java/dev/openfeature/sdk/OpenFeatureClient.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ private <T> FlagEvaluationDetails<T> evaluateFlag(FlagValueType type, String key
135135
OpenFeatureError error = ExceptionUtils.instantiateErrorByErrorCode(
136136
details.getErrorCode(),
137137
details.getErrorMessage());
138-
details.setValue(defaultValue);
138+
enrichDetailsWithErrorDefaults(defaultValue, details);
139139
hookSupport.errorHooks(type, afterHookContext, error, mergedHooks, hints);
140140
} else {
141141
hookSupport.afterHooks(type, afterHookContext, details, mergedHooks, hints);
@@ -150,8 +150,7 @@ private <T> FlagEvaluationDetails<T> evaluateFlag(FlagValueType type, String key
150150
details.setErrorCode(ErrorCode.GENERAL);
151151
}
152152
details.setErrorMessage(e.getMessage());
153-
details.setValue(defaultValue);
154-
details.setReason(Reason.ERROR.toString());
153+
enrichDetailsWithErrorDefaults(defaultValue, details);
155154
hookSupport.errorHooks(type, afterHookContext, e, mergedHooks, hints);
156155
} finally {
157156
hookSupport.afterAllHooks(type, afterHookContext, mergedHooks, hints);
@@ -160,6 +159,11 @@ private <T> FlagEvaluationDetails<T> evaluateFlag(FlagValueType type, String key
160159
return details;
161160
}
162161

162+
private static <T> void enrichDetailsWithErrorDefaults(T defaultValue, FlagEvaluationDetails<T> details) {
163+
details.setValue(defaultValue);
164+
details.setReason(Reason.ERROR.toString());
165+
}
166+
163167
/**
164168
* Merge invocation contexts with API, transaction and client contexts.
165169
* Does not merge before context.

src/main/java/dev/openfeature/sdk/exceptions/FlagNotFoundError.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,8 @@
66

77
@SuppressWarnings("checkstyle:MissingJavadocType")
88
@StandardException
9-
public class FlagNotFoundError extends OpenFeatureError {
9+
public class FlagNotFoundError extends OpenFeatureErrorWithoutStacktrace {
1010
private static final long serialVersionUID = 1L;
1111
@Getter private final ErrorCode errorCode = ErrorCode.FLAG_NOT_FOUND;
1212

13-
@Override
14-
public synchronized Throwable fillInStackTrace() {
15-
return this;
16-
}
1713
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package dev.openfeature.sdk.exceptions;
2+
3+
import dev.openfeature.sdk.ErrorCode;
4+
import lombok.experimental.StandardException;
5+
6+
@SuppressWarnings("checkstyle:MissingJavadocType")
7+
@StandardException
8+
public abstract class OpenFeatureErrorWithoutStacktrace extends OpenFeatureError {
9+
private static final long serialVersionUID = 1L;
10+
11+
@Override
12+
public synchronized Throwable fillInStackTrace() {
13+
return this;
14+
}
15+
}

src/main/java/dev/openfeature/sdk/exceptions/ProviderNotReadyError.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
@SuppressWarnings("checkstyle:MissingJavadocType")
88
@StandardException
9-
public class ProviderNotReadyError extends OpenFeatureError {
9+
public class ProviderNotReadyError extends OpenFeatureErrorWithoutStacktrace {
1010
private static final long serialVersionUID = 1L;
1111
@Getter private final ErrorCode errorCode = ErrorCode.PROVIDER_NOT_READY;
1212
}

src/main/java/dev/openfeature/sdk/exceptions/TypeMismatchError.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* The type of the flag value does not match the expected type.
99
*/
1010
@StandardException
11-
public class TypeMismatchError extends OpenFeatureError {
11+
public class TypeMismatchError extends OpenFeatureErrorWithoutStacktrace {
1212
private static final long serialVersionUID = 1L;
1313

1414
@Getter private final ErrorCode errorCode = ErrorCode.TYPE_MISMATCH;

src/test/java/dev/openfeature/sdk/FlagEvaluationSpecTest.java

+2
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ public void initialize(EvaluationContext evaluationContext) throws Exception {
264264
FlagEvaluationDetails<Boolean> details = c.getBooleanDetails("key", defaultValue);
265265
assertEquals(ErrorCode.FLAG_NOT_FOUND, details.getErrorCode());
266266
assertEquals(TestConstants.BROKEN_MESSAGE, details.getErrorMessage());
267+
assertEquals(Reason.ERROR.toString(), details.getReason());
267268
assertEquals(defaultValue, details.getValue());
268269
}
269270

@@ -279,6 +280,7 @@ public void initialize(EvaluationContext evaluationContext) throws Exception {
279280
FlagEvaluationDetails<Boolean> details = c.getBooleanDetails("key", defaultValue);
280281
assertEquals(ErrorCode.FLAG_NOT_FOUND, details.getErrorCode());
281282
assertEquals(TestConstants.BROKEN_MESSAGE, details.getErrorMessage());
283+
assertEquals(Reason.ERROR.toString(), details.getReason());
282284
assertEquals(defaultValue, details.getValue());
283285
}
284286

0 commit comments

Comments
 (0)