Skip to content

Commit

Permalink
Guard against unformattable caller name
Browse files Browse the repository at this point in the history
  • Loading branch information
jnyrup committed Jan 22, 2022
1 parent 9b2d8e2 commit 460ca13
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Src/FluentAssertions/Execution/MessageBuilder.cs
Expand Up @@ -91,7 +91,14 @@ private string FormatArgumentPlaceholders(string failureMessage, object[] failur
{
string[] values = failureArgs.Select(a => Formatter.ToString(a, formattingOptions)).ToArray();

return string.Format(CultureInfo.InvariantCulture, failureMessage, values);
try
{
return string.Format(CultureInfo.InvariantCulture, failureMessage, values);
}
catch (FormatException formatException)
{
return $"**WARNING** failure message '{failureMessage}' could not be formatted with string.Format{Environment.NewLine}{formatException.StackTrace}";
}
}

private string SanitizeReason(string reason)
Expand Down
1 change: 1 addition & 0 deletions docs/_pages/releases.md
Expand Up @@ -21,6 +21,7 @@ sidebar:
* `OccurredEvent` ordering on monitored object is now done via thread-safe counter - [#1773](https://github.com/fluentassertions/fluentassertions/pull/1773)
* Avoid a `NullReferenceException` when testing an application compiled with .NET Native - [#1776](https://github.com/fluentassertions/fluentassertions/pull/1776)
* `[Not]Contain(key, value)` for dictionary-like enumerables incorrectly checked if the key was present - [#1786](https://github.com/fluentassertions/fluentassertions/pull/1786)
* Avoid throwing a `FormatException` when caller name determination returns an unformattable string - [#1788](https://github.com/fluentassertions/fluentassertions/pull/1788)

## 6.3.0

Expand Down

0 comments on commit 460ca13

Please sign in to comment.