Skip to content

Refactor: Scope CA1031/CA2000 suppressions to specific call sites with inline justification #2

Description

@coderabbitai

Background

In the current implementation, CA1031 (do not catch general exception types) and CA2000 (dispose objects before losing scope) are suppressed globally in src/CryptoExchanges.Net.Binance/CryptoExchanges.Net.Binance.csproj via the NoWarn property:

<NoWarn>$(NoWarn);CA1812;CA1056;CA1031;CA2000;CA1305;CA1032;CS1591</NoWarn>

This was a deliberate maintainer decision to keep the initial PR unblocked, but project-wide suppression can mask real exception-handling and disposal defects in runtime-critical HTTP paths.

Goal

Remove CA1031 and CA2000 from the project-level NoWarn list and instead add targeted #pragma warning disable / #pragma warning restore suppressions (or [SuppressMessage] attributes) at the smallest possible scope in the files where these warnings legitimately fire, each accompanied by an inline comment explaining why the broad catch or the non-disposed resource is justified in that specific context.

Files likely affected

  • src/CryptoExchanges.Net.Binance/BinanceHttpClient.cs — broad catch blocks in EnsureSuccessAsync
  • src/CryptoExchanges.Net.Binance/BinanceExchangeClient.csPingAsync catch-all, SocketsHttpHandler / HttpClient ownership
  • src/CryptoExchanges.Net.DependencyInjection/ServiceCollectionExtensions.csHttpClient / BinanceExchangeClient factory lambdas

Acceptance criteria

  • CA1031 removed from project-level NoWarn
  • CA2000 removed from project-level NoWarn
  • Each remaining suppression is scoped to a single method/block with a justification comment
  • All 31 existing tests continue to pass with zero build errors

References

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions