From 949d53cada68bee8e80d113357fa6df8d425d3c1 Mon Sep 17 00:00:00 2001 From: Thomas Poignant Date: Tue, 9 Apr 2024 14:28:11 +0200 Subject: [PATCH] fix: Add missing error message when an error occurred (#256) ## This PR - Add missing error message when an error occurred ### Related Issues Fixes #255 --------- Signed-off-by: Thomas Poignant --- src/OpenFeature/OpenFeatureClient.cs | 2 +- test/OpenFeature.Tests/OpenFeatureClientTests.cs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/OpenFeature/OpenFeatureClient.cs b/src/OpenFeature/OpenFeatureClient.cs index c8513e8b..77cd8754 100644 --- a/src/OpenFeature/OpenFeatureClient.cs +++ b/src/OpenFeature/OpenFeatureClient.cs @@ -262,7 +262,7 @@ private async Task> EvaluateFlag( { this._logger.LogError(ex, "Error while evaluating flag {FlagKey}", flagKey); var errorCode = ex is InvalidCastException ? ErrorType.TypeMismatch : ErrorType.General; - evaluation = new FlagEvaluationDetails(flagKey, defaultValue, errorCode, Reason.Error, string.Empty); + evaluation = new FlagEvaluationDetails(flagKey, defaultValue, errorCode, Reason.Error, string.Empty, ex.Message); await this.TriggerErrorHooks(allHooksReversed, hookContext, ex, options).ConfigureAwait(false); } finally diff --git a/test/OpenFeature.Tests/OpenFeatureClientTests.cs b/test/OpenFeature.Tests/OpenFeatureClientTests.cs index 05965c51..9509eb8a 100644 --- a/test/OpenFeature.Tests/OpenFeatureClientTests.cs +++ b/test/OpenFeature.Tests/OpenFeatureClientTests.cs @@ -178,6 +178,7 @@ public async Task OpenFeatureClient_Should_Return_DefaultValue_When_Type_Mismatc var evaluationDetails = await client.GetObjectDetails(flagName, defaultValue); evaluationDetails.ErrorType.Should().Be(ErrorType.TypeMismatch); + evaluationDetails.ErrorMessage.Should().Be(new InvalidCastException().Message); _ = mockedFeatureProvider.Received(1).ResolveStructureValue(flagName, defaultValue, Arg.Any());