{"record":{"id":"d3dc9e732cd1c861","repo":"App-vNext/Polly","slug":"value-must-be-greater-than-zero-d3dc9e","errorCode":null,"errorMessage":"Value must be greater than zero.","messagePattern":"Value must be greater than zero\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Polly/CircuitBreaker/AdvancedCircuitBreakerTResultSyntax.cs","lineNumber":228,"sourceCode":"    /// <exception cref=\"ArgumentNullException\">Thrown when <paramref name=\"onBreak\"/> is <see langword=\"null\"/>.</exception>\n    /// <exception cref=\"ArgumentNullException\">Thrown when <paramref name=\"onReset\"/> is <see langword=\"null\"/>.</exception>\n    /// <exception cref=\"ArgumentNullException\">Thrown when <paramref name=\"onHalfOpen\"/> is <see langword=\"null\"/>.</exception>\n    /// <remarks>(see \"Release It!\" by Michael T. Nygard fi).</remarks>\n    public static CircuitBreakerPolicy<TResult> AdvancedCircuitBreaker<TResult>(\n        this PolicyBuilder<TResult> policyBuilder,\n        double failureThreshold,\n        TimeSpan samplingDuration,\n        int minimumThroughput,\n        TimeSpan durationOfBreak,\n        Action<DelegateResult<TResult>, CircuitState, TimeSpan, Context> onBreak,\n        Action<Context> onReset,\n        Action onHalfOpen)\n    {\n        var resolutionOfCircuit = TimeSpan.FromTicks(AdvancedCircuitController<EmptyStruct>.ResolutionOfCircuitTimer);\n\n        if (failureThreshold <= 0)\n        {\n            throw new ArgumentOutOfRangeException(nameof(failureThreshold), \"Value must be greater than zero.\");\n        }\n\n        if (failureThreshold > 1)\n        {\n            throw new ArgumentOutOfRangeException(nameof(failureThreshold), \"Value must be less than or equal to one.\");\n        }\n\n        if (samplingDuration < resolutionOfCircuit)\n        {\n            throw new ArgumentOutOfRangeException(nameof(samplingDuration), $\"Value must be equal to or greater than {resolutionOfCircuit.TotalMilliseconds} milliseconds. This is the minimum resolution of the CircuitBreaker timer.\");\n        }\n\n        if (minimumThroughput <= 1)\n        {\n            throw new ArgumentOutOfRangeException(nameof(minimumThroughput), \"Value must be greater than one.\");\n        }\n\n        if (durationOfBreak < TimeSpan.Zero)","sourceCodeStart":210,"sourceCodeEnd":246,"githubUrl":"https://github.com/App-vNext/Polly/blob/d0e46bdb1ee11ea50d0e4b6846d2633d6bc09bac/src/Polly/CircuitBreaker/AdvancedCircuitBreakerTResultSyntax.cs#L210-L246","documentation":"Thrown by the legacy v7 Polly AdvancedCircuitBreaker<T> syntax when the failureThreshold argument is zero or negative. failureThreshold is the failure ratio (0,1] at which the advanced circuit opens, so any value <= 0 is meaningless. The guard fires at policy BUILD time (inside the syntax extension), not when the policy executes.","triggerScenarios":"Calling Policy.Handle<...>().AdvancedCircuitBreaker(failureThreshold: 0, ...) or AdvancedCircuitBreaker(failureThreshold: -0.5, ...). The check is `failureThreshold <= 0`.","commonSituations":"Configuring the threshold from a config file where the value is missing/defaulted to 0, or computing it as failures/total when total is 0 (yielding 0). Passing an integer literal 0 where a percentage was intended (e.g. thinking 0 means 0%).","solutions":["Set failureThreshold to a ratio strictly greater than 0 and at most 1, e.g. 0.5 for 50%.","If the value comes from configuration, validate it is in (0,1] before passing it to the policy.","When computing a ratio dynamically, guard against a zero denominator before division."],"exampleFix":"// before\nPolicy.Handle<HttpRequestException>()\n    .AdvancedCircuitBreaker(\n        failureThreshold: 0,\n        samplingDuration: TimeSpan.FromSeconds(10),\n        minimumThroughput: 10,\n        durationOfBreak: TimeSpan.FromSeconds(30),\n        onBreak: (_, __, ___, ____) => { },\n        onReset: _ => { },\n        onHalfOpen: () => { });\n\n// after\nPolicy.Handle<HttpRequestException>()\n    .AdvancedCircuitBreaker(\n        failureThreshold: 0.5,\n        samplingDuration: TimeSpan.FromSeconds(10),\n        minimumThroughput: 10,\n        durationOfBreak: TimeSpan.FromSeconds(30),\n        onBreak: (_, __, ___, ____) => { },\n        onReset: _ => { },\n        onHalfOpen: () => { });","handlingStrategy":"validation","validationCode":"if (failureThreshold <= 0 || failureThreshold > 1)\n    throw new ArgumentOutOfRangeException(nameof(failureThreshold), \"failureThreshold must be in (0,1].\");","typeGuard":"static bool IsValidFailureThreshold(double t) => t > 0 && t <= 1;","tryCatchPattern":null,"preventionTips":["Centralize circuit-breaker construction behind a factory that validates all inputs once.","Bind failureThreshold through a strongly-typed options object validated at startup.","Treat failureThreshold as a ratio, never a percentage or count."],"tags":["circuit-breaker","argument-validation","legacy-api","configuration"],"backgroundTag":null,"analyzedSha":"d0e46bdb1ee11ea50d0e4b6846d2633d6bc09bac","analyzedAt":"2026-08-13T16:36:01.959Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}