From 32160c423e56e89245a5f6a2eeed14f08e785d27 Mon Sep 17 00:00:00 2001 From: basgys Date: Sun, 15 Mar 2026 15:37:25 +0100 Subject: [PATCH] fix: remove dead code and fix handling consistency MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit WithAcceptedErrors has been storing into opts.isErrorAccepted, a field that is never read — making the option silently inert. Remove the dead field and make WithAcceptedErrors an explicit no-op, updating its deprecation notice to reflect this. Align the errRejected switch case in WithAdaptiveThrottle to use the same unwrap-then-fallthrough pattern already used in Throttle and Throttle[T], removing a structural inconsistency with identical observable behaviour. Fix a typo in the DefaultAcceptedErrors deprecation comment: DefaultRejectedErrors → IsRejectedErro --- adaptive.go | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/adaptive.go b/adaptive.go index 57a9dca..39f1292 100644 --- a/adaptive.go +++ b/adaptive.go @@ -204,11 +204,10 @@ type AdaptiveThrottleOption struct { } type adaptiveThrottleOptions struct { - k float64 - minRate float64 - d time.Duration - isErrorAccepted func(err error) bool - validate func(p Priority, priorities int) (Priority, error) + k float64 + minRate float64 + d time.Duration + validate func(p Priority, priorities int) (Priority, error) } // WithAdaptiveThrottleRatio sets the ratio of the measured success rate and the rate that the throttle @@ -241,15 +240,10 @@ func WithAdaptiveThrottleWindow(d time.Duration) AdaptiveThrottleOption { }} } -// Deprecated: Wrap errors with RejectedError instead and use the global DefaultRejectedErrors. -// -// WithAcceptedErrors sets the function that determines whether an error should -// be considered for the throttling. When the call to fn returns true, the error -// is not counted towards the throttling. +// Deprecated: Wrap errors with RejectedError instead, or override the global IsRejectedError. +// This option has no effect and will be removed in a future version. func WithAcceptedErrors(fn func(err error) bool) AdaptiveThrottleOption { - return AdaptiveThrottleOption{func(opts *adaptiveThrottleOptions) { - opts.isErrorAccepted = fn - }} + return AdaptiveThrottleOption{func(opts *adaptiveThrottleOptions) {}} } // WithPriorityValidator sets the function that validates input priority values. @@ -368,10 +362,10 @@ func WithAdaptiveThrottle[T any]( case err == nil: at.accept(priority, now) case errors.Is(err, errRejected{}): - at.reject(priority, now) - // Unwrap error to return the original error to the caller err = err.(errRejected).inner + + fallthrough case IsRejectedError(err): at.reject(priority, now) default: @@ -419,7 +413,7 @@ type ( ) var ( - // Deprecated: Override `IsRejectedError` instead and/or wrap errors with `RejectedError`. + // Deprecated: Override IsRejectedError instead and/or wrap errors with RejectedError. // // DefaultAcceptedErrors is the default function used to determine whether // an error should be considered for the throttling.