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

CA2200: Rethrow to preserve stack details - should not warn when throwing different exception #4280

Closed
buyaa-n opened this issue Oct 2, 2020 · 6 comments · Fixed by #4285
Labels
False_Positive A diagnostic is reported for non-problematic case

Comments

@buyaa-n
Copy link
Contributor

buyaa-n commented Oct 2, 2020

Analyzer

Diagnostic ID: CA2200: Rethrow to preserve stack details

Analyzer source

SDK: Built-in CA analyzers in .NET 5 SDK or later

Version: SDK 5.0.100-preview.8

Describe the bug

The caught exception ex is only thrown when it is mapped into a different exception by the MapSendException(...) method. The analyzer should not warn in this case, further I would assume CA2200 should not warn when the catch block is throwing a different exception (mappedEx) than the catched exception (ex)

    try
    {
          ... 
    }
    catch (Exception ex) when (MapSendException(ex, cancellationToken, out Exception mappedEx))
    {
        throw mappedEx;
    }

The exact warning found here, related to dotnet/runtime#42957 (comment)

Expected behavior

Should not warn in above case

Actual behavior

Warning

@Youssef1313
Copy link
Member

A similar case is being tested:

@Evangelink Was this fixed in your re-write of the analyzer? or it should have been working from before the rewrite?

@mavasani
Copy link
Contributor

mavasani commented Oct 3, 2020

@buyaa-n Can you test with the latest package from https://dev.azure.com/dnceng/public/_packaging?_a=package&feed=dotnet6&package=Microsoft.CodeAnalysis.NetAnalyzers&protocolType=NuGet&version=6.0.0-preview1.20501.5&view=overview? I suspect @Evangelink's recent fix in master would have fixed this. We should consider backporting the change to release/dotnet5-rc2 branch if that is the case.

@buyaa-n
Copy link
Contributor Author

buyaa-n commented Oct 3, 2020

A similar case is being tested:
@Evangelink Was this fixed in your re-write of the analyzer?

Yep, it is the same case, looks already fixed

@buyaa-n Can you test with the latest package from https://dev.azure.com/dnceng/public/_packaging?_a=package&feed=dotnet6&package=Microsoft.CodeAnalysis.NetAnalyzers&protocolType=NuGet&version=6.0.0-preview1.20501.5&view=overview? I suspect @Evangelink's recent fix in master would have fixed this. We should consider backporting the change to release/dotnet5-rc2 branch if that is the case.

Yep i used RC2 branch, not master, agree we should port it to RC2

@buyaa-n
Copy link
Contributor Author

buyaa-n commented Oct 3, 2020

@Youssef1313
Copy link
Member

@buyaa-n Interesting! Let me add a test and debug it.

@Evangelink Evangelink added 4 - In Review False_Positive A diagnostic is reported for non-problematic case labels Oct 3, 2020
@Evangelink
Copy link
Member

Evangelink commented Oct 3, 2020

I didn't consider this case, honestly that's the first time I am seeing this pattern :)

@Youssef1313 has already filed a PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
False_Positive A diagnostic is reported for non-problematic case
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants