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 CA1032 warning #2194

Merged
merged 5 commits into from
Jul 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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 src/Polly/Polly.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<ProjectType>Library</ProjectType>
<MutationScore>70</MutationScore>
<IncludePollyUsings>true</IncludePollyUsings>
<NoWarn>$(NoWarn);CA1010;CA1031;CA1032;CA1051;CA1062;CA1063;CA1064;CA1710;CA1716;CA1724;CA1805;CA1815;CA1816;CA2211</NoWarn>
<NoWarn>$(NoWarn);CA1010;CA1031;CA1051;CA1062;CA1063;CA1064;CA1710;CA1716;CA1724;CA1805;CA1815;CA1816;CA2211</NoWarn>
<NoWarn>$(NoWarn);S2223;S3215;S3246;S3971;S4039;S4457</NoWarn>
<!--Public API Analyzers: We do not need to fix these as it would break compatibility with released Polly versions-->
<NoWarn>$(NoWarn);RS0037;</NoWarn>
Expand Down
27 changes: 27 additions & 0 deletions src/Polly/RateLimit/RateLimitRejectedException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,33 @@ public class RateLimitRejectedException : ExecutionRejectedException
/// </summary>
public TimeSpan RetryAfter { get; private set; }

/// <summary>
/// Initializes a new instance of the <see cref="RateLimitRejectedException"/> class.
/// </summary>
public RateLimitRejectedException()
: base("The operation could not be executed because it was rejected by the rate limit.")
{
}

/// <summary>
/// Initializes a new instance of the <see cref="RateLimitRejectedException"/> class.
/// </summary>
/// <param name="message">The message that describes the error.</param>
public RateLimitRejectedException(string message)
: base(message)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="RateLimitRejectedException"/> class.
/// </summary>
/// <param name="message">The message that describes the error.</param>
/// <param name="inner">The inner exception.</param>
public RateLimitRejectedException(string message, Exception inner)
: base(message, inner)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="RateLimitRejectedException"/> class.
/// </summary>
Expand Down
22 changes: 22 additions & 0 deletions src/Polly/Utilities/TimedLock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,30 @@ private class Sentinel

internal class LockTimeoutException : Exception
{
/// <summary>
/// Initializes a new instance of the <see cref="LockTimeoutException"/> class.
/// </summary>
public LockTimeoutException()
: base("Timeout waiting for lock")
{
}

/// <summary>
/// Initializes a new instance of the <see cref="LockTimeoutException"/> class.
/// </summary>
/// <param name="message">The message that describes the error.</param>
public LockTimeoutException(string message)
: base(message)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="LockTimeoutException"/> class.
/// </summary>
/// <param name="message">The message that describes the error.</param>
/// <param name="innerException">The inner exception.</param>
public LockTimeoutException(string message, Exception innerException)
: base(message, innerException)
{
}
}
35 changes: 35 additions & 0 deletions test/Polly.Specs/RateLimit/RateLimitRejectedExceptionTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
namespace Polly.Specs.RateLimit;

public class RateLimitRejectedExceptionTests
{
[Fact]
public void Ctor_Ok()
{
const string Dummy = "dummy";
var exception = new InvalidOperationException();
var retryAfter = TimeSpan.FromSeconds(4);

new RateLimitRejectedException().Message.Should().Be("The operation could not be executed because it was rejected by the rate limit.");
new RateLimitRejectedException(Dummy).Message.Should().Be(Dummy);

var rate = new RateLimitRejectedException(Dummy, exception);
rate.Message.Should().Be(Dummy);
rate.InnerException.Should().Be(exception);

new RateLimitRejectedException(retryAfter).RetryAfter.Should().Be(retryAfter);
new RateLimitRejectedException(retryAfter).Message.Should().Be($"The operation has been rate-limited and should be retried after {retryAfter}");

rate = new RateLimitRejectedException(retryAfter, exception);
rate.RetryAfter.Should().Be(retryAfter);
rate.InnerException.Should().Be(exception);

rate = new RateLimitRejectedException(retryAfter, Dummy);
rate.RetryAfter.Should().Be(retryAfter);
rate.Message.Should().Be(Dummy);

rate = new RateLimitRejectedException(retryAfter, Dummy, exception);
rate.RetryAfter.Should().Be(retryAfter);
rate.Message.Should().Be(Dummy);
rate.InnerException.Should().Be(exception);
}
}
18 changes: 18 additions & 0 deletions test/Polly.Specs/Utilities/LockTimeoutExceptionTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace Polly.Specs.Utilities;

public class LockTimeoutExceptionTests
{
[Fact]
public void Ctor_Ok()
{
const string Dummy = "dummy";
var exception = new InvalidOperationException();

new LockTimeoutException().Message.Should().Be("Timeout waiting for lock");
new LockTimeoutException(Dummy).Message.Should().Be(Dummy);

var rate = new LockTimeoutException(Dummy, exception);
rate.Message.Should().Be(Dummy);
rate.InnerException.Should().Be(exception);
}
}