Skip to content

Commit 00a5115

Browse files
committed
improve error logs for evaluation failure
Signed-off-by: Kavindu Dodanduwa <[email protected]>
1 parent 8845242 commit 00a5115

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ private <T> FlagEvaluationDetails<T> evaluateFlag(FlagValueType type, String key
137137
details = FlagEvaluationDetails.from(providerEval, key);
138138
hookSupport.afterHooks(type, hookCtx, details, mergedHooks, hints);
139139
} catch (Exception e) {
140-
log.error("Unable to correctly evaluate flag with key {} due to exception {}", key, e.getMessage());
140+
log.error("Unable to correctly evaluate flag with key '{}'", key, e);
141141
if (details == null) {
142142
details = FlagEvaluationDetails.<T>builder().build();
143143
}

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

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dev.openfeature.sdk;
22

33
import static org.assertj.core.api.Assertions.assertThat;
4+
import static org.assertj.core.api.InstanceOfAssertFactories.optional;
45
import static org.junit.jupiter.api.Assertions.assertEquals;
56
import static org.junit.jupiter.api.Assertions.assertFalse;
67
import static org.junit.jupiter.api.Assertions.assertNull;
@@ -15,6 +16,8 @@
1516
import java.util.List;
1617
import java.util.Map;
1718

19+
import com.google.common.collect.ImmutableList;
20+
import dev.openfeature.sdk.exceptions.FlagNotFoundError;
1821
import io.cucumber.java.hu.Ha;
1922
import org.junit.jupiter.api.AfterEach;
2023
import org.junit.jupiter.api.Test;
@@ -206,7 +209,14 @@ private Client _client() {
206209
Client c = api.getClient();
207210
FlagEvaluationDetails<Boolean> result = c.getBooleanDetails("test", false);
208211
assertEquals(Reason.ERROR.toString(), result.getReason());
209-
assertThat(TEST_LOGGER.getLoggingEvents()).contains(LoggingEvent.error("Unable to correctly evaluate flag with key {} due to exception {}", "test", TestConstants.BROKEN_MESSAGE));
212+
213+
ImmutableList<LoggingEvent> loggingEvents = TEST_LOGGER.getLoggingEvents();
214+
assertThat(loggingEvents.size()).isGreaterThan(0);
215+
216+
LoggingEvent event = loggingEvents.get(0);
217+
assertThat(event.getMessage()).isEqualTo("Unable to correctly evaluate flag with key '{}'");
218+
assertThat(event.getThrowable().isPresent()).isTrue();
219+
assertThat(event.getThrowable().get()).isInstanceOf(FlagNotFoundError.class);
210220
}
211221

212222
@Specification(number="1.2.2", text="The client interface MUST define a metadata member or accessor, containing an immutable name field or accessor of type string, which corresponds to the name value supplied during client creation.")

0 commit comments

Comments
 (0)