Skip to content

Commit 7ec4ca1

Browse files
kylejuliandevWeihanLi
authored andcommitted
refactor: InMemoryProvider throwing when types mismatched (open-feature#442)
<!-- Please use this template for your pull request. --> <!-- Please use the sections that you need and delete other sections --> ## This PR <!-- add the description of the PR here --> - Update InMemoryProvider to return an ErrorType with a default value instead of throwing exceptions - Add unit test to cover the new behavior ### Related Issues <!-- add here the GitHub issue that this PR resolves if applicable --> Fixes open-feature#441 ### Notes <!-- any additional notes for this PR --> ### Follow-up Tasks <!-- anything that is related to this PR but not done here should be noted under this section --> <!-- if there is a need for a new issue, please link it here --> ### How to test <!-- if applicable, add testing instructions under this section --> Signed-off-by: Kyle Julian <38759683+kylejuliandev@users.noreply.github.com> Signed-off-by: Weihan Li <weihanli@outlook.com>
1 parent 6ebf3f2 commit 7ec4ca1

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/OpenFeature/Providers/Memory/InMemoryProvider.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System.Threading;
44
using System.Threading.Tasks;
55
using OpenFeature.Constant;
6-
using OpenFeature.Error;
76
using OpenFeature.Model;
87

98
namespace OpenFeature.Providers.Memory
@@ -112,7 +111,7 @@ private ResolutionDetails<T> Resolve<T>(string flagKey, T defaultValue, Evaluati
112111
return value.Evaluate(flagKey, defaultValue, context);
113112
}
114113

115-
throw new TypeMismatchException($"flag {flagKey} is not of type {typeof(T)}");
114+
return new ResolutionDetails<T>(flagKey, defaultValue, ErrorType.TypeMismatch, Reason.Error);
116115
}
117116
}
118117
}

test/OpenFeature.Tests/Providers/Memory/InMemoryProviderTests.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,14 @@ public async Task MissingFlag_ShouldReturnFlagNotFoundEvaluationFlag()
186186
}
187187

188188
[Fact]
189-
public async Task MismatchedFlag_ShouldThrow()
189+
public async Task MismatchedFlag_ShouldReturnTypeMismatchError()
190190
{
191-
await Assert.ThrowsAsync<TypeMismatchException>(() => this.commonProvider.ResolveStringValueAsync("boolean-flag", "nope", EvaluationContext.Empty));
191+
// Act
192+
var result = await this.commonProvider.ResolveStringValueAsync("boolean-flag", "nope", EvaluationContext.Empty);
193+
194+
// Assert
195+
Assert.Equal(Reason.Error, result.Reason);
196+
Assert.Equal(ErrorType.TypeMismatch, result.ErrorType);
192197
}
193198

194199
[Fact]

0 commit comments

Comments
 (0)