{"record":{"id":"acc6b0ecb1cb5bd7","repo":"App-vNext/Polly","slug":"sleepdurations-acc6b0","errorCode":null,"errorMessage":"sleepDurations","messagePattern":"sleepDurations","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Polly/Retry/RetryTResultSyntax.cs","lineNumber":509,"sourceCode":"        return policyBuilder.WaitAndRetry(sleepDurations, (outcome, span, _, ctx) => onRetry(outcome, span, ctx));\n    }\n\n    /// <summary>\n    /// Builds a <see cref=\"Policy{TResult}\"/> that will wait and retry as many times as there are provided <paramref name=\"sleepDurations\"/>\n    /// calling <paramref name=\"onRetry\"/> on each retry with the handled exception or result, current sleep duration, retry count and context data.\n    /// On each retry, the duration to wait is the current <paramref name=\"sleepDurations\"/> item.\n    /// </summary>\n    /// <typeparam name=\"TResult\">The type of the result.</typeparam>\n    /// <param name=\"policyBuilder\">The policy builder.</param>\n    /// <param name=\"sleepDurations\">The sleep durations to wait for on each retry.</param>\n    /// <param name=\"onRetry\">The action to call on each retry.</param>\n    /// <returns>The policy instance.</returns>\n    /// <exception cref=\"ArgumentNullException\">Thrown when <paramref name=\"sleepDurations\"/> or <paramref name=\"onRetry\"/> is <see langword=\"null\"/>.</exception>\n    public static RetryPolicy<TResult> WaitAndRetry<TResult>(this PolicyBuilder<TResult> policyBuilder, IEnumerable<TimeSpan> sleepDurations, Action<DelegateResult<TResult>, TimeSpan, int, Context> onRetry)\n    {\n        if (sleepDurations == null)\n        {\n            throw new ArgumentNullException(nameof(sleepDurations));\n        }\n\n        if (onRetry == null)\n        {\n            throw new ArgumentNullException(nameof(onRetry));\n        }\n\n        return new RetryPolicy<TResult>(\n            policyBuilder,\n            onRetry,\n            sleepDurationsEnumerable: sleepDurations);\n    }\n\n    /// <summary>\n    /// Builds a <see cref=\"Policy{TResult}\"/> that will wait and retry indefinitely until the action succeeds.\n    ///     On each retry, the duration to wait is calculated by calling <paramref name=\"sleepDurationProvider\" /> with\n    ///     the current retry number (1 for first retry, 2 for second etc).\n    /// </summary>","sourceCodeStart":491,"sourceCodeEnd":527,"githubUrl":"https://github.com/App-vNext/Polly/blob/d0e46bdb1ee11ea50d0e4b6846d2633d6bc09bac/src/Polly/Retry/RetryTResultSyntax.cs#L491-L527","documentation":"ArgumentNullException thrown at construction by WaitAndRetry<TResult>(IEnumerable<TimeSpan> sleepDurations, Action<DelegateResult<TResult>, TimeSpan, int, Context> onRetry) when sleepDurations is null. This is the canonical full-detail overload; it validates sleepDurations first and rejects null with parameter name 'sleepDurations' because the policy iterates the collection to drive each retry.","triggerScenarios":"Calling policyBuilder.WaitAndRetry<TResult>(null, onRetry), or passing a null IEnumerable<TimeSpan> field (e.g. a config list that failed to bind) as the sleepDurations argument.","commonSituations":"Configuration binding for the duration list returned null; developer passed a list variable that was never initialized; empty vs null confusion (empty list is valid, null is not).","solutions":["Pass a non-null collection, even empty: Array.Empty<TimeSpan>() or new[] { TimeSpan.FromSeconds(1) }.","Initialize the duration list from config with a non-null default (e.g. ?? Array.Empty<TimeSpan>()).","Validate the config binding before building the policy."],"exampleFix":"// before\nvar p = Policy.HandleResult<int>(r => r == 0).WaitAndRetry(_config.Backoffs, onRetry); // _config.Backoffs is null\n\n// after\nvar backoffs = _config.Backoffs ?? new[] { TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(5) };\nvar p = Policy.HandleResult<int>(r => r == 0).WaitAndRetry(backoffs, onRetry);","handlingStrategy":"validation","validationCode":"var backoffs = sleepDurations ?? throw new InvalidOperationException(\"sleepDurations required.\");\nvar policy = Policy.HandleResult<T>(pred).WaitAndRetry(backoffs, onRetry);","typeGuard":"static bool IsDurations(IEnumerable<TimeSpan> d) => d is not null;","tryCatchPattern":null,"preventionTips":["Distinguish empty (valid, 0 retries) from null (invalid): coalesce to Array.Empty<TimeSpan>() or a default list.","Validate config bindings return non-null.","Enable nullable reference types."],"tags":["argument-null","wait-and-retry","sleep-durations","validation","polly-v7","legacy","config"],"backgroundTag":null,"analyzedSha":"d0e46bdb1ee11ea50d0e4b6846d2633d6bc09bac","analyzedAt":"2026-08-13T16:36:01.959Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}