Skip to content

Improve error message on data row mismatch #4996

@nohwnd

Description

@nohwnd
Member

Summary

datarow mismatch tells me that some indices have mismatches in data. This message is precise, but not very clear (to me).

Background and Motivation

Image

        [TestMethod]
        [DataRow("Luxury Car", "Alice Johnson", 1500, "https://example.com/luxurycar.jpg", "https://example.com/luxurycar")]
        [DataRow("Luxury Car", "Alice Johnson", 1500.00, "https://example.com/luxurycar.jpg", "https://example.com/luxurycar")]
        [DataRow("Diamond Ring", "Bob Brown", 2000.00, "https://example.com/diamondring.jpg", "https://example.com/diamondring")]
        public void AddGift_ShouldRejectExpensiveGifts(string name, string reservedBy, decimal price, string imageUrl, string link)
        {
            // Arrange
            var gift = new Gift(name, reservedBy, price, imageUrl, link);

            // Act & Assert
            Assert.ThrowsException<ArgumentException>(() => Program.AddGift(gift), "Gift price cannot exceed $1,000.");
        }

The warning is very precise, and probably wants to show me that there is error in the second parameter in the attribute, and also in the second parameter in the signature, but to me it reads as (x,y) coordinates and the error is not obvious to me, especially since double and decimal are both numbers.

Proposed Feature

Reword the warning to say: DataRow argument types do not match method parameter types. Parameter price expects decimal type, but the provided value has type double. (and the same for other mismatches... Parameter imageUrl expects string, but the provided value has type int.)

Alternative Designs

Activity

Youssef1313

Youssef1313 commented on Feb 12, 2025

@Youssef1313
Member

Yes, the wording isn't ideal. I thought we had this reported before but can't find an existing issue.

nohwnd

nohwnd commented on Feb 12, 2025

@nohwnd
MemberAuthor

I could not find it either (I used "indices" as the keyword), so it was probably just (or also) me complaining in a chat.

Evangelink

Evangelink commented on Jun 18, 2025

@Evangelink
Member

Please copilot fix the analyzer message to have something easier to grasp.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

Relationships

None yet

    Participants

    @nohwnd@Evangelink@Youssef1313

    Issue actions

      Improve error message on data row mismatch · Issue #4996 · microsoft/testfx