Skip to content

Commit

Permalink
Fix minor mistakes (#77)
Browse files Browse the repository at this point in the history
* Fix logging of failed GetValue(Async)/GetValueDetails(Async) calls

* Remove unintended setter of IPercentageOption.VariationId

* Fix XML documentation of Comparator.Contains/NotContains
  • Loading branch information
adams85 authored Jul 26, 2023
1 parent e3c33cb commit 843d64a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 33 deletions.
68 changes: 38 additions & 30 deletions src/ConfigCatClient/ConfigCatClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -419,24 +419,26 @@ public async Task<IReadOnlyCollection<string>> GetAllKeysAsync(CancellationToken
public IReadOnlyDictionary<string, object?> GetAllValues(User? user = null)
{
const string defaultReturnValue = "empty dictionary";
EvaluationDetails[]? evaluationDetailsArray = null;
Dictionary<string, object?> result;
EvaluationDetails[]? evaluationDetailsArray;
IReadOnlyList<Exception>? evaluationExceptions;
user ??= this.defaultUser;
try
{
var settings = GetSettings();
evaluationDetailsArray = this.configEvaluator.EvaluateAll(settings.Value, user, settings.RemoteConfig, this.logger, defaultReturnValue, out var exceptions);
if (exceptions is { Count: > 0 })
{
throw new AggregateException(exceptions);
}
evaluationDetailsArray = this.configEvaluator.EvaluateAll(settings.Value, user, settings.RemoteConfig, this.logger, defaultReturnValue, out evaluationExceptions);
result = evaluationDetailsArray.ToDictionary(details => details.Key, details => details.Value);
}
catch (Exception ex)
{
this.logger.SettingEvaluationError(nameof(GetAllValues), defaultReturnValue, ex);
evaluationDetailsArray ??= ArrayUtils.EmptyArray<EvaluationDetails>();
return new Dictionary<string, object?>();
}

var result = evaluationDetailsArray.ToDictionary(details => details.Key, details => details.Value);
if (evaluationExceptions is { Count: > 0 })
{
this.logger.SettingEvaluationError(nameof(GetAllValues), "evaluation result", new AggregateException(evaluationExceptions));
}

foreach (var evaluationDetails in evaluationDetailsArray)
{
Expand All @@ -450,16 +452,15 @@ public async Task<IReadOnlyCollection<string>> GetAllKeysAsync(CancellationToken
public async Task<IReadOnlyDictionary<string, object?>> GetAllValuesAsync(User? user = null, CancellationToken cancellationToken = default)
{
const string defaultReturnValue = "empty dictionary";
EvaluationDetails[]? evaluationDetailsArray = null;
Dictionary<string, object?> result;
EvaluationDetails[]? evaluationDetailsArray;
IReadOnlyList<Exception>? evaluationExceptions;
user ??= this.defaultUser;
try
{
var settings = await GetSettingsAsync(cancellationToken).ConfigureAwait(false);
evaluationDetailsArray = this.configEvaluator.EvaluateAll(settings.Value, user, settings.RemoteConfig, this.logger, defaultReturnValue, out var exceptions);
if (exceptions is { Count: > 0 })
{
throw new AggregateException(exceptions);
}
evaluationDetailsArray = this.configEvaluator.EvaluateAll(settings.Value, user, settings.RemoteConfig, this.logger, defaultReturnValue, out evaluationExceptions);
result = evaluationDetailsArray.ToDictionary(details => details.Key, details => details.Value);
}
catch (OperationCanceledException ex) when (ex.CancellationToken == cancellationToken)
{
Expand All @@ -468,10 +469,13 @@ public async Task<IReadOnlyCollection<string>> GetAllKeysAsync(CancellationToken
catch (Exception ex)
{
this.logger.SettingEvaluationError(nameof(GetAllValuesAsync), defaultReturnValue, ex);
evaluationDetailsArray ??= ArrayUtils.EmptyArray<EvaluationDetails>();
return new Dictionary<string, object?>();
}

var result = evaluationDetailsArray.ToDictionary(details => details.Key, details => details.Value);
if (evaluationExceptions is { Count: > 0 })
{
this.logger.SettingEvaluationError(nameof(GetAllValuesAsync), "evaluation result", new AggregateException(evaluationExceptions));
}

foreach (var evaluationDetails in evaluationDetailsArray)
{
Expand All @@ -485,21 +489,23 @@ public async Task<IReadOnlyCollection<string>> GetAllKeysAsync(CancellationToken
public IReadOnlyList<EvaluationDetails> GetAllValueDetails(User? user = null)
{
const string defaultReturnValue = "empty list";
EvaluationDetails[]? evaluationDetailsArray = null;
EvaluationDetails[]? evaluationDetailsArray;
IReadOnlyList<Exception>? evaluationExceptions;
user ??= this.defaultUser;
try
{
var settings = GetSettings();
evaluationDetailsArray = this.configEvaluator.EvaluateAll(settings.Value, user, settings.RemoteConfig, this.logger, defaultReturnValue, out var exceptions);
if (exceptions is { Count: > 0 })
{
throw new AggregateException(exceptions);
}
evaluationDetailsArray = this.configEvaluator.EvaluateAll(settings.Value, user, settings.RemoteConfig, this.logger, defaultReturnValue, out evaluationExceptions);
}
catch (Exception ex)
{
this.logger.SettingEvaluationError(nameof(GetAllValueDetails), defaultReturnValue, ex);
evaluationDetailsArray ??= ArrayUtils.EmptyArray<EvaluationDetails>();
return ArrayUtils.EmptyArray<EvaluationDetails>();
}

if (evaluationExceptions is { Count: > 0 })
{
this.logger.SettingEvaluationError(nameof(GetAllValueDetails), "evaluation result", new AggregateException(evaluationExceptions));
}

foreach (var evaluationDetails in evaluationDetailsArray)
Expand All @@ -514,16 +520,13 @@ public IReadOnlyList<EvaluationDetails> GetAllValueDetails(User? user = null)
public async Task<IReadOnlyList<EvaluationDetails>> GetAllValueDetailsAsync(User? user = null, CancellationToken cancellationToken = default)
{
const string defaultReturnValue = "empty list";
EvaluationDetails[]? evaluationDetailsArray = null;
EvaluationDetails[]? evaluationDetailsArray;
IReadOnlyList<Exception>? evaluationExceptions;
user ??= this.defaultUser;
try
{
var settings = await GetSettingsAsync(cancellationToken).ConfigureAwait(false);
evaluationDetailsArray = this.configEvaluator.EvaluateAll(settings.Value, user, settings.RemoteConfig, this.logger, defaultReturnValue, out var exceptions);
if (exceptions is { Count: > 0 })
{
throw new AggregateException(exceptions);
}
evaluationDetailsArray = this.configEvaluator.EvaluateAll(settings.Value, user, settings.RemoteConfig, this.logger, defaultReturnValue, out evaluationExceptions);
}
catch (OperationCanceledException ex) when (ex.CancellationToken == cancellationToken)
{
Expand All @@ -532,7 +535,12 @@ public async Task<IReadOnlyList<EvaluationDetails>> GetAllValueDetailsAsync(User
catch (Exception ex)
{
this.logger.SettingEvaluationError(nameof(GetAllValueDetailsAsync), defaultReturnValue, ex);
evaluationDetailsArray ??= ArrayUtils.EmptyArray<EvaluationDetails>();
return ArrayUtils.EmptyArray<EvaluationDetails>();
}

if (evaluationExceptions is { Count: > 0 })
{
this.logger.SettingEvaluationError(nameof(GetAllValueDetailsAsync), "evaluation result", new AggregateException(evaluationExceptions));
}

foreach (var evaluationDetails in evaluationDetailsArray)
Expand Down
4 changes: 2 additions & 2 deletions src/ConfigCatClient/Models/Comparator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ public enum Comparator : byte
NotIn = 1,

/// <summary>
/// Does the comparison value contain the comparison attribute as a substring?
/// Is the comparison value contained by the comparison attribute as a substring?
/// </summary>
Contains = 2,

/// <summary>
/// Does the comparison value not contain the comparison attribute as a substring?
/// Is the comparison value not contained by the comparison attribute as a substring?
/// </summary>
NotContains = 3,

Expand Down
2 changes: 1 addition & 1 deletion src/ConfigCatClient/Models/RolloutPercentageItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public interface IPercentageOption
/// <summary>
/// Variation ID.
/// </summary>
string? VariationId { get; set; }
string? VariationId { get; }
}

internal sealed class RolloutPercentageItem : IPercentageOption
Expand Down

0 comments on commit 843d64a

Please sign in to comment.