{"record":{"id":"f69eee6e2b09840f","repo":"elsa-workflows/elsa-core","slug":"capacity-must-be-greater-than-zero","errorCode":null,"errorMessage":"Capacity must be greater than zero.","messagePattern":"Capacity must be greater than zero\\.","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/modules/Elsa.Diagnostics.OpenTelemetry/Providers/InMemory/RingBuffer.cs","lineNumber":13,"sourceCode":"namespace Elsa.Diagnostics.OpenTelemetry.Providers.InMemory;\n\npublic class RingBuffer<T>\n{\n    private readonly Queue<T> _items = new();\n    private readonly object _lock = new();\n    private readonly int _capacity;\n    private long _droppedCount;\n\n    public RingBuffer(int capacity)\n    {\n        if (capacity <= 0)\n            throw new ArgumentOutOfRangeException(nameof(capacity), \"Capacity must be greater than zero.\");\n\n        _capacity = capacity;\n    }\n\n    public long DroppedCount\n    {\n        get\n        {\n            lock (_lock)\n                return _droppedCount;\n        }\n    }\n\n    public void Add(T item)\n    {\n        lock (_lock)\n        {\n            if (_items.Count == _capacity)","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/elsa-workflows/elsa-core/blob/fe9217bdfa0e27f0e09e45006eb6898f616e513d/src/modules/Elsa.Diagnostics.OpenTelemetry/Providers/InMemory/RingBuffer.cs#L1-L31","documentation":"The RingBuffer<T> constructor requires a strictly positive capacity. A capacity of zero or a negative value cannot back a bounded ring, so the constructor throws ArgumentOutOfRangeException naming the capacity parameter before any state is stored.","triggerScenarios":"Constructing new RingBuffer<T>(0), a negative size, or registering an OpenTelemetry in-memory provider whose configured buffer capacity option resolves to 0/negative (e.g. unset int config bound to default(int)).","commonSituations":"Appsettings binding where the capacity key is missing and the property defaults to 0; arithmetic computing capacity (e.g. size in MB * 1024) evaluating to 0; copying sample config with capacity commented out.","solutions":["Pass a positive capacity, e.g. new RingBuffer<LogRecord>(1000).","Fix the bound configuration so the capacity option defaults to a positive value or is explicitly set.","Clamp/validate configured values at options validation time so 0 never reaches the constructor."],"exampleFix":"// before\nvar buffer = new RingBuffer<LogRecord>(config.BufferCapacity); // 0 when unset\n\n// after\nvar capacity = Math.Max(1, config.BufferCapacity);\nvar buffer = new RingBuffer<LogRecord>(capacity);","handlingStrategy":"validation","validationCode":"if (capacity <= 0)\n    throw new InvalidOperationException($\"Ring buffer capacity must be positive, got {capacity}.\");\nvar buffer = new RingBuffer<T>(capacity);","typeGuard":null,"tryCatchPattern":"try { buffer = new RingBuffer<T>(configuredCapacity); }\ncatch (ArgumentOutOfRangeException ex) { buffer = new RingBuffer<T>(DefaultCapacity); }","preventionTips":["Give capacity options a positive default and validate configured values at startup.","Clamp config-derived capacities with Math.Max(1, value) before constructing buffers."],"tags":["argument-validation","ring-buffer","configuration"],"backgroundTag":"argument-out-of-range","analyzedSha":"fe9217bdfa0e27f0e09e45006eb6898f616e513d","analyzedAt":"2026-09-13T20:32:34.702Z","contentChangedAt":"2026-09-13T20:32:34.702Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}