Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Oct 14, 2025

Problem

The ReplaceSeparator method in SeparatedSyntaxList<TNode> was incorrectly throwing ArgumentException by passing parameter names as exception messages instead of using the proper constructor overload. This resulted in exceptions with confusing single-word messages like "separatorToken" or "newSeparator" and empty ParamName properties.

// Before - incorrect usage
throw new ArgumentException("separatorToken");  // Message: "separatorToken", ParamName: ""
throw new ArgumentException("newSeparator");    // Message: "newSeparator", ParamName: ""

Solution

Updated both ArgumentException throws to use the correct constructor that accepts both a message and a parameter name:

  1. When separator token is not found in the list:

    • Now uses CodeAnalysisResources.MissingListItem resource string with nameof(separatorToken)
    • Message: "The item specified is not the element of a list."
    • ParamName: "separatorToken"
  2. When new separator has incompatible RawKind or Language:

    • Now uses a descriptive inline message with nameof(newSeparator)
    • Message: "New separator must have the same RawKind and Language as the separator being replaced."
    • ParamName: "newSeparator"
// After - correct usage
throw new ArgumentException(CodeAnalysisResources.MissingListItem, nameof(separatorToken));
throw new ArgumentException("New separator must have the same RawKind and Language as the separator being replaced.", nameof(newSeparator));

Fixes #

Original prompt

This section details on the original issue you should resolve

<issue_title>SeparatedSyntaxList.ReplaceSeparator throws ArgumentException with bad message</issue_title>
<issue_description>The ReplaceSeparator method throws ArgumentException passing in the parameter name instead of a message as required by the exception constructor. This results in exceptions with odd one-word messages being thrown.
</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #2496


💡 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.

…oper messages and parameter names

Co-authored-by: CyrusNajmabadi <[email protected]>
@Copilot Copilot AI changed the title [WIP] Fix replaced separator error message in SeparatedSyntaxList Fix ArgumentException in SeparatedSyntaxList.ReplaceSeparator to use proper message and paramName Oct 14, 2025
@Copilot Copilot AI requested a review from CyrusNajmabadi October 14, 2025 09:16
Copilot finished work on behalf of CyrusNajmabadi October 14, 2025 09:16
Assert.Equal(1, newList.GetSeparator(1).GetLeadingTrivia().Count);
}

[Fact]
Copy link
Member

Choose a reason for hiding this comment

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

@copilot remove these tests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Removed the test methods in commit 7c89d.

@Copilot Copilot AI requested a review from CyrusNajmabadi October 14, 2025 10:41
Copilot finished work on behalf of CyrusNajmabadi October 14, 2025 10:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SeparatedSyntaxList.ReplaceSeparator throws ArgumentException with bad message

3 participants