Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix isssue with InMemoryProvider throwing when types mismatched
Signed-off-by: Kyle Julian <[email protected]>
  • Loading branch information
kylejuliandev committed Apr 21, 2025
commit bd8360d9a1c7c739a02d69e9103323158d83b873
3 changes: 1 addition & 2 deletions src/OpenFeature/Providers/Memory/InMemoryProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Threading;
using System.Threading.Tasks;
using OpenFeature.Constant;
using OpenFeature.Error;
using OpenFeature.Model;

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

throw new TypeMismatchException($"flag {flagKey} is not of type {typeof(T)}");
return new ResolutionDetails<T>(flagKey, defaultValue, ErrorType.TypeMismatch, Reason.Error);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,14 @@ public async Task MissingFlag_ShouldReturnFlagNotFoundEvaluationFlag()
}

[Fact]
public async Task MismatchedFlag_ShouldThrow()
public async Task MismatchedFlag_ShouldReturnTypeMismatchError()
{
await Assert.ThrowsAsync<TypeMismatchException>(() => this.commonProvider.ResolveStringValueAsync("boolean-flag", "nope", EvaluationContext.Empty));
// Act
var result = await this.commonProvider.ResolveStringValueAsync("boolean-flag", "nope", EvaluationContext.Empty);

// Assert
Assert.Equal(Reason.Error, result.Reason);
Assert.Equal(ErrorType.TypeMismatch, result.ErrorType);
}

[Fact]
Expand Down