Skip to content

Commit

Permalink
Fix typos & minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
adams85 committed Oct 27, 2023
1 parent 834bc4d commit c175c7d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
3 changes: 1 addition & 2 deletions src/ConfigCatClient/Evaluation/EvaluateLogHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,10 @@ private static IndentedTextBuilder AppendPercentageOptions(this IndentedTextBuil

private static IndentedTextBuilder AppendTargetingRuleThenPart(this IndentedTextBuilder builder, TargetingRule targetingRule, bool newLine, bool appendPercentageOptions = false, string? percentageOptionsAttribute = null)
{
var percentageOptions = targetingRule.PercentageOptions;

(newLine ? builder.NewLine() : builder.Append(" "))
.Append("THEN");

var percentageOptions = targetingRule.PercentageOptions;
if (percentageOptions is not { Length: > 0 })
{
return builder.Append($" '{targetingRule.SimpleValue?.Value ?? default}'");
Expand Down
28 changes: 14 additions & 14 deletions src/ConfigCatClient/Evaluation/RolloutEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public EvaluateResult Evaluate<T>(T defaultValue, ref EvaluateContext context, [
if (context.Setting.SettingType != Setting.UnknownType && context.Setting.SettingType != expectedSettingType)
{
throw new InvalidOperationException(
"The type of a setting must match the type of the specified default value "
"The type of a setting must match the type of the specified default value. "
+ $"Setting's type was {context.Setting.SettingType} but the default value's type was {typeof(T)}. "
+ $"Please use a default value which corresponds to the setting type {context.Setting.SettingType}.");
}
Expand Down Expand Up @@ -159,13 +159,10 @@ private bool TryEvaluateTargetingRules(TargetingRule[] targetingRules, ref Evalu
logBuilder?.DecreaseIndent();
return true;
}
else
{
logBuilder?
.NewLine(TargetingRuleIgnoredMessage)
.DecreaseIndent();
continue;
}

logBuilder?
.NewLine(TargetingRuleIgnoredMessage)
.DecreaseIndent();
}

result = default;
Expand Down Expand Up @@ -237,14 +234,14 @@ private bool TryEvaluatePercentageOptions(PercentageOption[] percentageOptions,
continue;
}

var percentageOptionValue = percentageOption.Value.GetValue(context.Setting.SettingType, throwIfInvalid: false);
var percentageOptionValue = percentageOption.Value.GetValue(throwIfInvalid: false);
logBuilder?.NewLine().Append($"- Hash value {hashValue} selects % option {i + 1} ({percentageOption.Percentage}%), '{percentageOptionValue ?? EvaluateLogHelper.InvalidValuePlaceholder}'.");

result = new EvaluateResult(percentageOption, matchedTargetingRule: targetingRule, matchedPercentageOption: percentageOption);
return true;
}

throw new InvalidOperationException("Sum of percentage option percentages are less than 100).");
throw new InvalidOperationException("Sum of percentage option percentages are less than 100.");
}

private bool EvaluateConditions<TCondition>(TCondition[] conditions, TargetingRule? targetingRule, string contextSalt, ref EvaluateContext context, out string? error)
Expand Down Expand Up @@ -301,12 +298,15 @@ private bool EvaluateConditions<TCondition>(TCondition[] conditions, TargetingRu
throw new InvalidOperationException(); // execution should never get here
}

if (targetingRule is null || conditions.Length > 1)
if (logBuilder is not null)
{
logBuilder?.AppendConditionConsequence(conditionResult);
}
if (targetingRule is null || conditions.Length > 1)
{
logBuilder.AppendConditionConsequence(conditionResult);
}

logBuilder?.DecreaseIndent();
logBuilder.DecreaseIndent();
}

if (!conditionResult)
{
Expand Down

0 comments on commit c175c7d

Please sign in to comment.