{"record":{"id":"54d3a07e59f5064e","repo":"App-vNext/Polly","slug":"value-must-be-greater-than-zero-54d3a0","errorCode":null,"errorMessage":"Value must be greater than zero.","messagePattern":"Value must be greater than zero\\.","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Polly/CircuitBreaker/CircuitBreakerSyntax.cs","lineNumber":182,"sourceCode":"    /// </para>\n    /// </summary>\n    /// <param name=\"policyBuilder\">The policy builder.</param>\n    /// <param name=\"exceptionsAllowedBeforeBreaking\">The number of exceptions that are allowed before opening the circuit.</param>\n    /// <param name=\"durationOfBreak\">The duration the circuit will stay open before resetting.</param>\n    /// <param name=\"onBreak\">The action to call when the circuit transitions to an <see cref=\"CircuitState.Open\"/> state.</param>\n    /// <param name=\"onReset\">The action to call when the circuit resets to a <see cref=\"CircuitState.Closed\"/> state.</param>\n    /// <param name=\"onHalfOpen\">The action to call when the circuit transitions to <see cref=\"CircuitState.HalfOpen\"/> state, ready to try action executions again. </param>\n    /// <returns>The policy instance.</returns>\n    /// <remarks>(see \"Release It!\" by Michael T. Nygard fi).</remarks>\n    /// <exception cref=\"ArgumentOutOfRangeException\">exceptionsAllowedBeforeBreaking;Value must be greater than zero.</exception>\n    /// <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    public static CircuitBreakerPolicy CircuitBreaker(this PolicyBuilder policyBuilder, int exceptionsAllowedBeforeBreaking, TimeSpan durationOfBreak, Action<Exception, CircuitState, TimeSpan, Context> onBreak, Action<Context> onReset, Action onHalfOpen)\n    {\n        if (exceptionsAllowedBeforeBreaking <= 0)\n        {\n            throw new ArgumentOutOfRangeException(nameof(exceptionsAllowedBeforeBreaking), \"Value must be greater than zero.\");\n        }\n\n        if (durationOfBreak < TimeSpan.Zero)\n        {\n            throw new ArgumentOutOfRangeException(nameof(durationOfBreak), \"Value must be greater than zero.\");\n        }\n\n        if (onBreak == null)\n        {\n            throw new ArgumentNullException(nameof(onBreak));\n        }\n\n        if (onReset == null)\n        {\n            throw new ArgumentNullException(nameof(onReset));\n        }\n\n        if (onHalfOpen == null)","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/App-vNext/Polly/blob/d0e46bdb1ee11ea50d0e4b6846d2633d6bc09bac/src/Polly/CircuitBreaker/CircuitBreakerSyntax.cs#L164-L200","documentation":"Thrown by the legacy v7 sync CircuitBreaker syntax (non-generic) when exceptionsAllowedBeforeBreaking is <= 0. This is the number of handled exceptions permitted before the simple circuit opens; it must be at least 1. Fires at policy construction time (not when the policy runs).","triggerScenarios":"Calling Policy.Handle<...>().CircuitBreaker(exceptionsAllowedBeforeBreaking: 0, ...). The check is `exceptionsAllowedBeforeBreaking <= 0`.","commonSituations":"Passing 0 from missing/blank configuration, or intending 'always open' but using 0 instead of 1.","solutions":["Set exceptionsAllowedBeforeBreaking to at least 1 (commonly 3-10).","Validate the configured value is a positive integer at startup.","Use 1 if you want the circuit to open on the first handled exception."],"exampleFix":"// before\nPolicy.Handle<HttpRequestException>()\n    .CircuitBreaker(\n        exceptionsAllowedBeforeBreaking: 0,\n        durationOfBreak: TimeSpan.FromSeconds(30),\n        onBreak: (_, __, ___, ____) => { },\n        onReset: _ => { },\n        onHalfOpen: () => { });\n\n// after\nPolicy.Handle<HttpRequestException>()\n    .CircuitBreaker(\n        exceptionsAllowedBeforeBreaking: 5,\n        durationOfBreak: TimeSpan.FromSeconds(30),\n        onBreak: (_, __, ___, ____) => { },\n        onReset: _ => { },\n        onHalfOpen: () => { });","handlingStrategy":"validation","validationCode":"if (exceptionsAllowedBeforeBreaking <= 0)\n    throw new ArgumentOutOfRangeException(nameof(exceptionsAllowedBeforeBreaking), \"Must be >= 1.\");","typeGuard":"static bool IsValidExceptionsAllowed(int n) => n >= 1;","tryCatchPattern":null,"preventionTips":["Use 1 when you want the circuit to open on the first handled exception.","Validate config yields a positive integer before constructing the policy.","Centralize breaker construction behind a validated factory."],"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"}