Skip to content

Commit

Permalink
Merge pull request #395 from NextTurn/message
Browse files Browse the repository at this point in the history
Add exception handler in DiagnosticResult.Message
  • Loading branch information
sharwell authored Oct 10, 2019
2 parents dd4adae + ef9e19f commit 61536ae
Showing 1 changed file with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,14 @@ public string? Message

if (MessageFormat != null)
{
return string.Format(MessageFormat.ToString(), MessageArguments ?? EmptyArguments);
try
{
return string.Format(MessageFormat.ToString(), MessageArguments ?? EmptyArguments);
}
catch (FormatException)
{
return MessageFormat.ToString();
}
}

return null;
Expand Down Expand Up @@ -273,19 +280,10 @@ public override string ToString()
builder.Append(" ");
builder.Append(Id);

try
var message = Message;
if (message != null)
{
var message = Message;
if (message != null)
{
builder.Append(": ").Append(message);
}
}
catch (FormatException)
{
// A message format is provided without arguments, so we print the unformatted string
Debug.Assert(MessageFormat != null, $"Assertion failed: {nameof(MessageFormat)} != null");
builder.Append(": ").Append(MessageFormat);
builder.Append(": ").Append(message);
}

return builder.ToString();
Expand Down

0 comments on commit 61536ae

Please sign in to comment.