Skip to content

Commit

Permalink
fix: improve error logs for evaluation failure (#276)
Browse files Browse the repository at this point in the history
improve error logs for evaluation failure

Signed-off-by: Kavindu Dodanduwa <kavindudodanduwa@gmail.com>
  • Loading branch information
Kavindu-Dodan authored Feb 3, 2023
1 parent 648518d commit 9349997
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/java/dev/openfeature/sdk/OpenFeatureClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ private <T> FlagEvaluationDetails<T> evaluateFlag(FlagValueType type, String key
details = FlagEvaluationDetails.from(providerEval, key);
hookSupport.afterHooks(type, hookCtx, details, mergedHooks, hints);
} catch (Exception e) {
log.error("Unable to correctly evaluate flag with key {} due to exception {}", key, e.getMessage());
log.error("Unable to correctly evaluate flag with key '{}'", key, e);
if (details == null) {
details = FlagEvaluationDetails.<T>builder().build();
}
Expand Down
12 changes: 11 additions & 1 deletion src/test/java/dev/openfeature/sdk/FlagEvaluationSpecTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.openfeature.sdk;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.InstanceOfAssertFactories.optional;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
Expand All @@ -15,6 +16,8 @@
import java.util.List;
import java.util.Map;

import com.google.common.collect.ImmutableList;
import dev.openfeature.sdk.exceptions.FlagNotFoundError;
import io.cucumber.java.hu.Ha;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -206,7 +209,14 @@ private Client _client() {
Client c = api.getClient();
FlagEvaluationDetails<Boolean> result = c.getBooleanDetails("test", false);
assertEquals(Reason.ERROR.toString(), result.getReason());
assertThat(TEST_LOGGER.getLoggingEvents()).contains(LoggingEvent.error("Unable to correctly evaluate flag with key {} due to exception {}", "test", TestConstants.BROKEN_MESSAGE));

ImmutableList<LoggingEvent> loggingEvents = TEST_LOGGER.getLoggingEvents();
assertThat(loggingEvents.size()).isGreaterThan(0);

LoggingEvent event = loggingEvents.get(0);
assertThat(event.getMessage()).isEqualTo("Unable to correctly evaluate flag with key '{}'");
assertThat(event.getThrowable().isPresent()).isTrue();
assertThat(event.getThrowable().get()).isInstanceOf(FlagNotFoundError.class);
}

@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.")
Expand Down

0 comments on commit 9349997

Please sign in to comment.