Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing SDK: DiagnosticResult.Message throws System.FormatException #340

Closed
RikkiGibson opened this issue Jun 16, 2019 · 1 comment
Closed
Labels
Area-MS.CA.Testing Microsoft.CodeAnalysis.Testing fixed

Comments

@RikkiGibson
Copy link
Contributor

This can throw when the diagnostic message has format parameters '{0}', '{1}' etc. This is fine, but maybe the FormatException should be caught and rethrown in a way that's going to make sense/be
more easily actionable to users of the library.

Here's the exception you get:

System.FormatException
  HResult=0x80131537
  Message=Index (zero based) must be greater than or equal to zero and less than the size of the argument list.
  Source=System.Private.CoreLib
  StackTrace:
   at System.Text.StringBuilder.AppendFormatHelper(IFormatProvider provider, String format, ParamsArray args) in E:\A\_work\2188\s\src\mscorlib\shared\System\Text\StringBuilder.cs:line 1743
   at System.String.FormatHelper(IFormatProvider provider, String format, ParamsArray args) in E:\A\_work\2188\s\src\mscorlib\src\System\String.Manipulation.cs:line 513
   at System.String.Format(String format, Object[] args) in E:\A\_work\2188\s\src\mscorlib\src\System\String.Manipulation.cs:line 473
   at Microsoft.CodeAnalysis.Testing.DiagnosticResult.get_Message() in /_/src/Tools/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.Analyzer.Testing/DiagnosticResult.cs:line 61

Instead of giving a message like this:

"Index (zero based) must be greater than or equal to zero and less than the size of the argument list"

Let's say something like:

$"{diagnosticResult.ToString()} didn't contain enough arguments for all the format variables in the diagnostic message {diagnosticResult.MessageFormat}."
@sharwell sharwell added the Area-MS.CA.Testing Microsoft.CodeAnalysis.Testing label Sep 16, 2019
@sharwell
Copy link
Member

sharwell commented Nov 4, 2019

This was fixed by @NextTurn in #395

@sharwell sharwell closed this as completed Nov 4, 2019
@sharwell sharwell added the fixed label Nov 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-MS.CA.Testing Microsoft.CodeAnalysis.Testing fixed
Projects
None yet
Development

No branches or pull requests

2 participants