diff --git a/src/LaunchDarkly.OpenFeature.ServerProvider/EvaluationDetailExtensions.cs b/src/LaunchDarkly.OpenFeature.ServerProvider/EvaluationDetailExtensions.cs
index de98d92..d13d47b 100644
--- a/src/LaunchDarkly.OpenFeature.ServerProvider/EvaluationDetailExtensions.cs
+++ b/src/LaunchDarkly.OpenFeature.ServerProvider/EvaluationDetailExtensions.cs
@@ -21,7 +21,7 @@ internal static class EvaluationDetailExtensions
///
/// Convert an into a string identifier.
- /// This string identifier is the same as we would use in a JSON representation.
+ /// Uses the OpenFeature equivalent where one exists, otherwise the LaunchDarkly identifier.
///
/// The value to convert
/// The value as a string
@@ -31,11 +31,11 @@ private static string ToIdentifier(this EvaluationReasonKind value)
switch (value)
{
case EvaluationReasonKind.Off:
- return "OFF";
+ return Reason.Disabled;
case EvaluationReasonKind.Fallthrough:
return "FALLTHROUGH";
case EvaluationReasonKind.TargetMatch:
- return "TARGET_MATCH";
+ return Reason.TargetingMatch;
case EvaluationReasonKind.RuleMatch:
return "RULE_MATCH";
case EvaluationReasonKind.PrerequisiteFailed:
@@ -115,7 +115,6 @@ private static ImmutableMetadata ToFlagMetadata(this EvaluationReason reason, in
/// The flag key that was evaluated
/// The type of the flag evaluation
/// The
- /// Thrown if the kind is not valid
public static ResolutionDetails ToResolutionDetails(this EvaluationDetail detail, string flagKey)
{
if (detail.Reason.Kind != EvaluationReasonKind.Error)
@@ -145,10 +144,9 @@ public static ResolutionDetails ToResolutionDetails(this EvaluationDetail<
break;
case EvaluationErrorKind.Exception:
case null:
+ default:
// All general errors.
break;
- default:
- throw new ArgumentOutOfRangeException();
}
return new ResolutionDetails(flagKey, detail.Value, errorType,
diff --git a/test/LaunchDarkly.OpenFeature.ServerProvider.Tests/EvaluationDetailExtensionsTest.cs b/test/LaunchDarkly.OpenFeature.ServerProvider.Tests/EvaluationDetailExtensionsTest.cs
index 714a40a..ac3a32e 100644
--- a/test/LaunchDarkly.OpenFeature.ServerProvider.Tests/EvaluationDetailExtensionsTest.cs
+++ b/test/LaunchDarkly.OpenFeature.ServerProvider.Tests/EvaluationDetailExtensionsTest.cs
@@ -22,7 +22,7 @@ public void ItCanHandleSuccessfulEvaluations()
[Fact]
public void ItCanHandleEachOfTheNonErrorEvaluationReasons()
{
- Assert.Equal("OFF",
+ Assert.Equal("DISABLED",
new EvaluationDetail(true, 10, EvaluationReason.OffReason)
.ToResolutionDetails("test-flag").Reason);
@@ -30,7 +30,7 @@ public void ItCanHandleEachOfTheNonErrorEvaluationReasons()
new EvaluationDetail(true, 10, EvaluationReason.FallthroughReason)
.ToResolutionDetails("test-flag").Reason);
- Assert.Equal("TARGET_MATCH",
+ Assert.Equal("TARGETING_MATCH",
new EvaluationDetail(true, 10, EvaluationReason.TargetMatchReason)
.ToResolutionDetails("test-flag").Reason);
@@ -75,6 +75,20 @@ public void ItCanHandleErrorTypes()
.ToResolutionDetails("test-flag").ErrorType);
}
+ [Fact]
+ public void ItMapsUnknownErrorKindsToGeneral()
+ {
+ var detail = new EvaluationDetail(false, null,
+ EvaluationReason.ErrorReason((EvaluationErrorKind)int.MaxValue));
+
+ var resolution = detail.ToResolutionDetails("test-flag");
+
+ Assert.False(resolution.Value);
+ Assert.Equal("ERROR", resolution.Reason);
+ Assert.Equal(ErrorType.General, resolution.ErrorType);
+ Assert.Null(resolution.Variant);
+ }
+
[Fact]
public void ItIncludesTheVariationIndexInFlagMetadata()
{