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

Fix SA1414 warning #2172

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bench/Polly.Benchmarks/Polly.Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
<Nullable>enable</Nullable>
<ProjectType>Benchmark</ProjectType>
<NoWarn>$(NoWarn);CA1822;SA1414;IDE0060</NoWarn>
<NoWarn>$(NoWarn);CA1822;IDE0060</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Polly/Bulkhead/BulkheadSemaphoreFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace Polly.Bulkhead;

internal static class BulkheadSemaphoreFactory
{
public static (SemaphoreSlim, SemaphoreSlim) CreateBulkheadSemaphores(int maxParallelization, int maxQueueingActions)
public static (SemaphoreSlim MaxParallelizationSemaphore, SemaphoreSlim MaxQueuedActionsSemaphore) CreateBulkheadSemaphores(int maxParallelization, int maxQueueingActions)
{
var maxParallelizationSemaphore = new SemaphoreSlim(maxParallelization, maxParallelization);

Expand Down
4 changes: 2 additions & 2 deletions src/Polly/Caching/IAsyncCacheProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public interface IAsyncCacheProvider
/// A <see cref="Task{TResult}" /> promising as Result a tuple whose first element is a value indicating whether
/// the key was found in the cache, and whose second element is the value from the cache (null if not found).
/// </returns>
Task<(bool, object?)> TryGetAsync(string key, CancellationToken cancellationToken, bool continueOnCapturedContext);
Task<(bool CacheHit, object? Result)> TryGetAsync(string key, CancellationToken cancellationToken, bool continueOnCapturedContext);
Copy link
Member

Choose a reason for hiding this comment

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

We can't make changes like this to the public interface. This is why the build is failing, because the public API no longer matches the baseline.

For public members, the warning just has to be suppressed. Otherwise it would be a breaking change for users.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Really. I've done something stupid


/// <summary>
/// Puts the specified value in the cache asynchronously.
Expand Down Expand Up @@ -46,7 +46,7 @@ public interface IAsyncCacheProvider<TResult>
/// A <see cref="Task{TResult}" /> promising as Result a tuple whose first element is a value indicating whether
/// the key was found in the cache, and whose second element is the value from the cache (default(TResult) if not found).
/// </returns>
Task<(bool, TResult?)> TryGetAsync(string key, CancellationToken cancellationToken, bool continueOnCapturedContext);
Task<(bool CacheHit, TResult? Result)> TryGetAsync(string key, CancellationToken cancellationToken, bool continueOnCapturedContext);

/// <summary>
/// Puts the specified value in the cache asynchronously.
Expand Down
4 changes: 2 additions & 2 deletions src/Polly/Caching/ISyncCacheProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public interface ISyncCacheProvider
/// A tuple whose first element is a value indicating whether the key was found in the cache,
/// and whose second element is the value from the cache (null if not found).
/// </returns>
(bool, object?) TryGet(string key);
(bool CacheHit, object? Result) TryGet(string key);

/// <summary>
/// Puts the specified value in the cache.
Expand All @@ -39,7 +39,7 @@ public interface ISyncCacheProvider<TResult>
/// A tuple whose first element is a value indicating whether the key was found in the cache,
/// and whose second element is the value from the cache (default(TResult) if not found).
/// </returns>
(bool, TResult?) TryGet(string key);
(bool CacheHit, TResult? Result) TryGet(string key);

/// <summary>
/// Puts the specified value in the cache.
Expand Down
1 change: 0 additions & 1 deletion src/Polly/Polly.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<IncludePollyUsings>true</IncludePollyUsings>
<NoWarn>$(NoWarn);CA1010;CA1031;CA1032;CA1033;CA1051;CA1062;CA1063;CA1064;CA1068;CA1710;CA1716;CA1724;CA1805;CA1815;CA1816;CA2211</NoWarn>
<NoWarn>$(NoWarn);S2223;S3215;S3246;S3971;S4039;S4049;S4457</NoWarn>
<NoWarn>$(NoWarn);SA1414</NoWarn>
<!--Public API Analyzers: We do not need to fix these as it would break compatibility with released Polly versions-->
<NoWarn>$(NoWarn);RS0037;</NoWarn>
</PropertyGroup>
Expand Down
8 changes: 4 additions & 4 deletions src/Polly/PublicAPI.Shipped.txt
Copy link
Member

Choose a reason for hiding this comment

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

As noted in my previous comment, all these changes should be reverted.

If we wanted to make them (which we don't), they would go in the Unshipped file because these members don't exist in any shipped version.

Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ Polly.Caching.DefaultCacheKeyStrategy.DefaultCacheKeyStrategy() -> void
Polly.Caching.DefaultCacheKeyStrategy.GetCacheKey(Polly.Context context) -> string
Polly.Caching.IAsyncCacheProvider
Polly.Caching.IAsyncCacheProvider.PutAsync(string key, object value, Polly.Caching.Ttl ttl, System.Threading.CancellationToken cancellationToken, bool continueOnCapturedContext) -> System.Threading.Tasks.Task
Polly.Caching.IAsyncCacheProvider.TryGetAsync(string key, System.Threading.CancellationToken cancellationToken, bool continueOnCapturedContext) -> System.Threading.Tasks.Task<(bool, object)>
Polly.Caching.IAsyncCacheProvider.TryGetAsync(string key, System.Threading.CancellationToken cancellationToken, bool continueOnCapturedContext) -> System.Threading.Tasks.Task<(bool CacheHit, object Result)>
Polly.Caching.IAsyncCacheProvider<TResult>
Polly.Caching.IAsyncCacheProvider<TResult>.PutAsync(string key, TResult value, Polly.Caching.Ttl ttl, System.Threading.CancellationToken cancellationToken, bool continueOnCapturedContext) -> System.Threading.Tasks.Task
Polly.Caching.IAsyncCacheProvider<TResult>.TryGetAsync(string key, System.Threading.CancellationToken cancellationToken, bool continueOnCapturedContext) -> System.Threading.Tasks.Task<(bool, TResult)>
Polly.Caching.IAsyncCacheProvider<TResult>.TryGetAsync(string key, System.Threading.CancellationToken cancellationToken, bool continueOnCapturedContext) -> System.Threading.Tasks.Task<(bool CacheHit, TResult Result)>
Polly.Caching.ICacheItemSerializer<TResult, TSerialized>
Polly.Caching.ICacheItemSerializer<TResult, TSerialized>.Deserialize(TSerialized objectToDeserialize) -> TResult
Polly.Caching.ICacheItemSerializer<TResult, TSerialized>.Serialize(TResult objectToSerialize) -> TSerialized
Expand All @@ -142,10 +142,10 @@ Polly.Caching.ICachePolicy
Polly.Caching.ICachePolicy<TResult>
Polly.Caching.ISyncCacheProvider
Polly.Caching.ISyncCacheProvider.Put(string key, object value, Polly.Caching.Ttl ttl) -> void
Polly.Caching.ISyncCacheProvider.TryGet(string key) -> (bool, object)
Polly.Caching.ISyncCacheProvider.TryGet(string key) -> (bool CacheHit, object Result)
Polly.Caching.ISyncCacheProvider<TResult>
Polly.Caching.ISyncCacheProvider<TResult>.Put(string key, TResult value, Polly.Caching.Ttl ttl) -> void
Polly.Caching.ISyncCacheProvider<TResult>.TryGet(string key) -> (bool, TResult)
Polly.Caching.ISyncCacheProvider<TResult>.TryGet(string key) -> (bool CacheHit, TResult Result)
Polly.Caching.ITtlStrategy
Polly.Caching.ITtlStrategy<TResult>
Polly.Caching.ITtlStrategy<TResult>.GetTtl(Polly.Context context, TResult result) -> Polly.Caching.Ttl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public async Task Single_generic_SerializingCacheProvider_should_not_deserialize
var stubCacheProvider = new StubCacheProvider();
string key = "some key";

stubCacheProvider.TryGet(key).Item1.Should().BeFalse();
stubCacheProvider.TryGet(key).CacheHit.Should().BeFalse();

AsyncSerializingCacheProvider<StubSerialized> serializingCacheProvider = new AsyncSerializingCacheProvider<StubSerialized>(stubCacheProvider.AsyncFor<StubSerialized>(), stubSerializer);
(bool cacheHit, object? fromCache) = await serializingCacheProvider.TryGetAsync(key, CancellationToken.None, false);
Expand Down Expand Up @@ -200,7 +200,7 @@ public async Task Single_generic_SerializingCacheProvider_from_extension_syntax_
var stubCacheProvider = new StubCacheProvider();
string key = "some key";

stubCacheProvider.TryGet(key).Item1.Should().BeFalse();
stubCacheProvider.TryGet(key).CacheHit.Should().BeFalse();

AsyncSerializingCacheProvider<StubSerialized> serializingCacheProvider = stubCacheProvider.AsyncFor<StubSerialized>().WithSerializer(stubSerializer);
(bool cacheHit, object? fromCache) = await serializingCacheProvider.TryGetAsync(key, CancellationToken.None, false);
Expand Down Expand Up @@ -322,7 +322,7 @@ public async Task Double_generic_SerializingCacheProvider_should_not_deserialize
var stubCacheProvider = new StubCacheProvider();
string key = "some key";

stubCacheProvider.TryGet(key).Item1.Should().BeFalse();
stubCacheProvider.TryGet(key).CacheHit.Should().BeFalse();

AsyncSerializingCacheProvider<ResultPrimitive, StubSerialized<ResultPrimitive>> serializingCacheProvider = new AsyncSerializingCacheProvider<ResultPrimitive, StubSerialized<ResultPrimitive>>(stubCacheProvider.AsyncFor<StubSerialized<ResultPrimitive>>(), stubTResultSerializer);
(bool cacheHit, ResultPrimitive? fromCache) = await serializingCacheProvider.TryGetAsync(key, CancellationToken.None, false);
Expand Down Expand Up @@ -411,7 +411,7 @@ public async Task Double_generic_SerializingCacheProvider_from_extension_syntax_
var stubCacheProvider = new StubCacheProvider();
string key = "some key";

stubCacheProvider.TryGet(key).Item1.Should().BeFalse();
stubCacheProvider.TryGet(key).CacheHit.Should().BeFalse();

AsyncSerializingCacheProvider<ResultPrimitive, StubSerialized<ResultPrimitive>> serializingCacheProvider =
stubCacheProvider.AsyncFor<StubSerialized<ResultPrimitive>>().WithSerializer(stubTResultSerializer);
Expand Down
8 changes: 4 additions & 4 deletions test/Polly.Specs/Caching/SerializingCacheProviderSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public void Single_generic_SerializingCacheProvider_should_not_deserialize_on_ge
var stubCacheProvider = new StubCacheProvider();
string key = "some key";

stubCacheProvider.TryGet(key).Item1.Should().BeFalse();
stubCacheProvider.TryGet(key).CacheHit.Should().BeFalse();

SerializingCacheProvider<StubSerialized> serializingCacheProvider = new SerializingCacheProvider<StubSerialized>(stubCacheProvider.For<StubSerialized>(), stubSerializer);
(bool cacheHit, object? fromCache) = serializingCacheProvider.TryGet(key);
Expand Down Expand Up @@ -200,7 +200,7 @@ public void Single_generic_SerializingCacheProvider_from_extension_syntax_should
var stubCacheProvider = new StubCacheProvider();
string key = "some key";

stubCacheProvider.TryGet(key).Item1.Should().BeFalse();
stubCacheProvider.TryGet(key).CacheHit.Should().BeFalse();

SerializingCacheProvider<StubSerialized> serializingCacheProvider = stubCacheProvider.For<StubSerialized>().WithSerializer(stubSerializer);
(bool cacheHit, object? fromCache) = serializingCacheProvider.TryGet(key);
Expand Down Expand Up @@ -322,7 +322,7 @@ public void Double_generic_SerializingCacheProvider_should_not_deserialize_on_ge
var stubCacheProvider = new StubCacheProvider();
string key = "some key";

stubCacheProvider.TryGet(key).Item1.Should().BeFalse();
stubCacheProvider.TryGet(key).CacheHit.Should().BeFalse();

SerializingCacheProvider<ResultPrimitive, StubSerialized<ResultPrimitive>> serializingCacheProvider = new SerializingCacheProvider<ResultPrimitive, StubSerialized<ResultPrimitive>>(stubCacheProvider.For<StubSerialized<ResultPrimitive>>(), stubTResultSerializer);
(bool cacheHit, ResultPrimitive fromCache) = serializingCacheProvider.TryGet(key);
Expand Down Expand Up @@ -413,7 +413,7 @@ public void Double_generic_SerializingCacheProvider_from_extension_syntax_should
var stubCacheProvider = new StubCacheProvider();
string key = "some key";

stubCacheProvider.TryGet(key).Item2.Should().BeNull();
stubCacheProvider.TryGet(key).Result.Should().BeNull();

SerializingCacheProvider<ResultPrimitive, StubSerialized<ResultPrimitive>> serializingCacheProvider =
stubCacheProvider.For<StubSerialized<ResultPrimitive>>().WithSerializer(stubTResultSerializer);
Expand Down
2 changes: 1 addition & 1 deletion test/Polly.Specs/Helpers/Caching/StubCacheProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public CacheItem(object? value, Ttl ttl)

private readonly Dictionary<string, CacheItem> _cachedValues = [];

public (bool, object?) TryGet(string key)
public (bool CacheHit, object? Result) TryGet(string key)
{
if (_cachedValues.ContainsKey(key))
{
Expand Down
Loading