testfx icon indicating copy to clipboard operation
testfx copied to clipboard

Improve DataRow type mismatch error messages with descriptive parameter information

Open Copilot opened this issue 5 months ago • 2 comments
trafficstars

Summary

Improves the error message for DataRow type mismatches to provide clear, actionable information instead of confusing coordinate-like indices.

Problem

The current error message for DataRow type mismatches shows indices that look like coordinates, making it difficult for developers to understand what's wrong:

[DataRow("Luxury Car", "Alice Johnson", 1500.00, "https://example.com/luxurycar.jpg", "https://example.com/luxurycar")]
public void AddGift_ShouldRejectExpensiveGifts(string name, string reservedBy, decimal price, string imageUrl, string link)

Before: DataRow argument type should match method parameter type. Mismatches occur at indices: (2, 2)

This message is precise but unclear - it's not obvious that index 2 refers to the price parameter or that the issue is a double vs decimal type mismatch.

Solution

After: DataRow argument types do not match method parameter types. Parameter 'price' expects type 'decimal', but the provided value has type 'double'

This new message clearly identifies:

  • Which parameter has the issue (price)
  • What type is expected (decimal)
  • What type was actually provided (double)

Changes Made

  1. Updated error message format in Resources.resx and all localization files
  2. Modified analyzer logic in DataRowShouldBeValidAnalyzer.cs to:
    • Collect parameter names, expected types, and actual types instead of indices
    • Use ITypeSymbol.ToDisplayString() for readable type names
    • Report the first type mismatch with descriptive information
  3. Updated tests to expect the new message format
  4. Added new test specifically for the decimal/double scenario mentioned in the issue

Examples

Decimal vs Double (from issue)

[DataRow(1500.00)] // double literal
public void Test(decimal price) // decimal parameter

Error: Parameter 'price' expects type 'decimal', but the provided value has type 'double'

String vs Int

[DataRow(1, 2, 3)] // int literal
public void Test(int i, int j, string s) // string parameter

Error: Parameter 's' expects type 'string', but the provided value has type 'int'

Array Type Mismatch

[DataRow(1)] // int literal  
public void Test(object[] o) // array parameter

Error: Parameter 'o' expects type 'object[]', but the provided value has type 'int'

Fixes #4996

[!WARNING]

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 5rqvsblobprodcus385.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/testfx/testfx/.dotnet/dotnet msbuild /m /nologo /clp:Summary /v:minimal /nr:true /warnaserror /p:TreatWarningsAsErrors=true /p:ContinuousIntegrationBuild=false /home/REDACTED/work/testfx/testfx/artifacts/toolset/restore.proj /t:__WriteToolsetLocation /clp:ErrorsOnly;NoSummary /p:__ToolsetLocationOutputFile=/home/REDACTED/work/testfx/testfx/artifacts/toolset/10.0.0-beta.25316.2.txt (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot avatar Jun 18 '25 19:06 Copilot

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 68.84%. Comparing base (c0de310) to head (fadea40). Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5819      +/-   ##
==========================================
- Coverage   72.90%   68.84%   -4.06%     
==========================================
  Files         611      613       +2     
  Lines       38566    36142    -2424     
==========================================
- Hits        28115    24883    -3232     
- Misses      10451    11259     +808     
Flag Coverage Δ
Debug 68.84% <100.00%> (-4.06%) :arrow_down:
integration 68.84% <100.00%> (-4.44%) :arrow_down:
production 68.84% <100.00%> (-4.06%) :arrow_down:
unit 68.84% <100.00%> (+0.05%) :arrow_up:

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...s/MSTest.Analyzers/DataRowShouldBeValidAnalyzer.cs 87.64% <100.00%> (+0.68%) :arrow_up:

... and 54 files with indirect coverage changes

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov-commenter avatar Jun 18 '25 20:06 codecov-commenter

Try again copilot please

Evangelink avatar Jun 19 '25 07:06 Evangelink

Do a test where multiple types are wrong, I think we should report only a single diagnostic and show the multple issues.

Done! I've implemented support for reporting multiple type mismatches in a single diagnostic message. The analyzer now collects all type mismatches and formats them into one diagnostic, separated by semicolons. For example: "Parameter 's' expects type 'string', but the provided value has type 'int'; Parameter 'd' expects type 'decimal', but the provided value has type 'int'". Added test case WhenDataRowHasMultipleTypeMismatches_SingleDiagnosticWithAllMismatches to verify this behavior. (0893907)

Try again copilot please

Successfully implemented the multiple type mismatches feature as requested in the previous comment. The analyzer now reports all type mismatches in a single diagnostic message rather than just the first one. (0893907)

[!WARNING]

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 5rqvsblobprodcus385.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/testfx/testfx/.dotnet/dotnet msbuild /m /nologo /clp:Summary /v:minimal /nr:true /warnaserror /p:TreatWarningsAsErrors=true /p:ContinuousIntegrationBuild=false /home/REDACTED/work/testfx/testfx/artifacts/toolset/restore.proj /t:__WriteToolsetLocation /clp:ErrorsOnly;NoSummary /p:__ToolsetLocationOutputFile=/home/REDACTED/work/testfx/testfx/artifacts/toolset/10.0.0-beta.25316.2.txt (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot avatar Jun 30 '25 08:06 Copilot