Skip to content

Improve DataRow type mismatch error messages with descriptive parameter information #5819

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

Merged
merged 9 commits into from
Jul 7, 2025

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jun 18, 2025

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.

@codecov-commenter
Copy link

codecov-commenter commented Jun 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

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%) ⬇️
integration 68.84% <100.00%> (-4.44%) ⬇️
production 68.84% <100.00%> (-4.06%) ⬇️
unit 68.84% <100.00%> (+0.05%) ⬆️

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%) ⬆️

... and 54 files with indirect coverage changes

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

@Evangelink
Copy link
Member

Try again copilot please

Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Improve error message on data row mismatch Improve DataRow type mismatch error messages with descriptive parameter information Jun 19, 2025
Copilot finished work on behalf of Evangelink June 19, 2025 07:38
Copy link
Member

@Evangelink Evangelink left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jun 30, 2025

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 Copilot AI requested a review from Evangelink June 30, 2025 08:44
Copilot finished work on behalf of Evangelink June 30, 2025 08:44
@Evangelink Evangelink marked this pull request as ready for review June 30, 2025 09:05
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
@Copilot Copilot AI requested a review from Evangelink June 30, 2025 09:12
Copilot finished work on behalf of Evangelink June 30, 2025 09:12
@Evangelink Evangelink enabled auto-merge (squash) July 3, 2025 13:40
@Evangelink Evangelink merged commit 093c672 into main Jul 7, 2025
8 checks passed
@Evangelink Evangelink deleted the copilot/fix-4996 branch July 7, 2025 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Error loading sessions

Retrying...

Successfully merging this pull request may close these issues.

Improve error message on data row mismatch
4 participants