From 2a59f7b621bc93faf0f85b4ff3ecc359b03bb049 Mon Sep 17 00:00:00 2001 From: NextTurn <45985406+NextTurn@users.noreply.github.com> Date: Sun, 23 Dec 2018 00:00:00 +0000 Subject: [PATCH 1/2] Add exception handler in DiagnosticResult.Message --- .../DiagnosticResult.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.Analyzer.Testing/DiagnosticResult.cs b/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.Analyzer.Testing/DiagnosticResult.cs index 5e801443f..c92d8dc98 100644 --- a/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.Analyzer.Testing/DiagnosticResult.cs +++ b/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.Analyzer.Testing/DiagnosticResult.cs @@ -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; From ef9e19ffebb410d345a12bbffc706105785abc3f Mon Sep 17 00:00:00 2001 From: NextTurn <45985406+NextTurn@users.noreply.github.com> Date: Mon, 31 Dec 2018 00:00:00 +0000 Subject: [PATCH 2/2] Remove handler in ToString --- .../DiagnosticResult.cs | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.Analyzer.Testing/DiagnosticResult.cs b/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.Analyzer.Testing/DiagnosticResult.cs index c92d8dc98..a3d1a7ccd 100644 --- a/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.Analyzer.Testing/DiagnosticResult.cs +++ b/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.Analyzer.Testing/DiagnosticResult.cs @@ -280,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();