Skip to content

Commit

Permalink
fix: make semver logging actually log context value that it failed to…
Browse files Browse the repository at this point in the history
… parse rather than allowing the logger to potentially crash (#200)
  • Loading branch information
sighphyre authored Jan 19, 2024
1 parent e1bed33 commit 649cdbb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public bool Evaluate(Constraint constraint, UnleashContext context)
SemanticVersion contextSemver;
if (!SemanticVersion.TryParse(contextValue, out contextSemver))
{
Logger.Info(() => "Couldn't parse version {0} from context");
Logger.Info(() => $"Couldn't parse version {contextValue} from context");
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,5 +251,27 @@ public void Release_Is_Greater_Than_RC_Inverted()
// Assert
result.Should().BeFalse();
}

[Test]
public void SemverConstraint_Handles_Invalid_Semver_Without_Raising_Exception()
{
// Arrange
var target = new SemverConstraintOperator();
var constraint = new Constraint(
"operator_semver_test",
Operator.SEMVER_GT,
false,
true,
"definitely.not.a.valid.semver"
);
var context = new UnleashContext();
context.Properties.Add("operator_semver_test", "also.definitely.not.a.semver");

// Act + Assert
Assert.DoesNotThrow(() =>
{
target.Evaluate(constraint, context);
});
}
}
}

0 comments on commit 649cdbb

Please sign in to comment.