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

RCS1140 - Don't require user to document exception types if caught in same method #1524

Merged

Conversation

Qluxzz
Copy link
Contributor

@Qluxzz Qluxzz commented Sep 15, 2024

There was no tests for RCS1140 so I added one based on the documentation for the rule.

When I was testing this rule I was not expecting it to require me to document exception types thrown but caught in the same method.

An example from a unit test I created

public void Foo(object parameter)
{
    try 
    {
        if (parameter == null)
            throw new ArgumentNullException(nameof(parameter));
    }
    catch (ArgumentNullException) {}
}

Here the exception is caught in the method but the analyzer for RCS1140 still require it to be documented on the method.

This PR checks if the exception type thrown in the method is also caught in the same method, and then removes the requirement to document it for the method.

@Qluxzz
Copy link
Contributor Author

Qluxzz commented Sep 15, 2024

@dotnet-policy-service agree

Copy link
Collaborator

@josefpihrt josefpihrt left a comment

Choose a reason for hiding this comment

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

Please update changelog.

@Qluxzz Qluxzz force-pushed the fix-required-to-document-caught-exceptions branch from 22c2600 to 7bc2b71 Compare September 22, 2024 11:51
@Qluxzz Qluxzz force-pushed the fix-required-to-document-caught-exceptions branch from b584e16 to dc4481b Compare September 27, 2024 10:25
josefpihrt
josefpihrt previously approved these changes Sep 27, 2024
Copy link
Collaborator

@josefpihrt josefpihrt left a comment

Choose a reason for hiding this comment

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

Great PR! Thanks for the contribution.

@josefpihrt josefpihrt merged commit bde6487 into dotnet:main Sep 27, 2024
17 checks passed
@Qluxzz Qluxzz deleted the fix-required-to-document-caught-exceptions branch September 30, 2024 14:28
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

Successfully merging this pull request may close these issues.

2 participants