From ba9bdf8a5208f88190965ca077bd2d62f9b7ffc0 Mon Sep 17 00:00:00 2001 From: Clement Date: Mon, 13 Nov 2023 11:52:29 +1100 Subject: [PATCH] More robust validation when setting leaky bucket state. --- .../Policies/LeakyBucketPolicy/LeakyBucket.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/ShopifySharp/Infrastructure/Policies/LeakyBucketPolicy/LeakyBucket.cs b/ShopifySharp/Infrastructure/Policies/LeakyBucketPolicy/LeakyBucket.cs index 74e0858a1..48332c3f4 100644 --- a/ShopifySharp/Infrastructure/Policies/LeakyBucketPolicy/LeakyBucket.cs +++ b/ShopifySharp/Infrastructure/Policies/LeakyBucketPolicy/LeakyBucket.cs @@ -59,8 +59,17 @@ internal LeakyBucket(int maximumAvailable, int restoreRatePerSecond, Func maximumAvailable) - throw new ArgumentOutOfRangeException(); + if (maximumAvailable <= 0) + throw new ArgumentOutOfRangeException($"{nameof(maximumAvailable)} ({maximumAvailable}) must be greater than zero"); + + if (currentlyAvailable < 0) + throw new ArgumentOutOfRangeException($"{nameof(currentlyAvailable)} ({currentlyAvailable}) must be positive or zero."); + + if (restoreRatePerSecond <= 0) + throw new ArgumentOutOfRangeException($"{nameof(restoreRatePerSecond)} ({restoreRatePerSecond}) must be greater than zero"); + + if (currentlyAvailable > maximumAvailable) + throw new ArgumentOutOfRangeException($"{nameof(currentlyAvailable)} ({currentlyAvailable}) must not be greater than {nameof(maximumAvailable)} ({maximumAvailable})"); lock (_lock) {