{"record":{"id":"ee4949d28230d038","repo":"AvaloniaUI/Avalonia","slug":"skip-count-must-be-bigger-than-zero","errorCode":null,"errorMessage":"Skip count must be bigger than zero","messagePattern":"Skip count must be bigger than zero","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Reactive/Observable.cs","lineNumber":105,"sourceCode":"\n    public static IObservable<TResult> CombineLatest<TFirst, TSecond, TResult>(\n        this IObservable<TFirst> first, IObservable<TSecond> second,\n        Func<TFirst, TSecond, TResult> resultSelector)\n    {\n        return new CombineLatest<TFirst, TSecond, TResult>(first, second, resultSelector);\n    }\n    \n    public static IObservable<TInput[]> CombineLatest<TInput>(\n        this IEnumerable<IObservable<TInput>> inputs)\n    {\n        return new CombineLatest<TInput, TInput[]>(inputs, items => items);\n    }\n\n    public static IObservable<T> Skip<T>(this IObservable<T> source, int skipCount)\n    {\n        if (skipCount <= 0)\n        {\n            throw new ArgumentException(\"Skip count must be bigger than zero\", nameof(skipCount));\n        }\n\n        return Create<T>(obs =>\n        {\n            var remaining = skipCount;\n            return source.Subscribe(new AnonymousObserver<T>(\n                input =>\n                {\n                    if (remaining <= 0)\n                    {\n                        obs.OnNext(input);\n                    }\n                    else\n                    {\n                        remaining--;\n                    }\n                }, obs.OnError, obs.OnCompleted));\n        });","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Reactive/Observable.cs#L87-L123","documentation":"Thrown by Observable.Skip<T> when skipCount is less than or equal to zero. Skip is meant to drop the first N notifications of a stream; skipping zero or a negative count is a programming error (use the source directly). Note the message says 'must be bigger than zero' and the guard is skipCount <= 0, so skipCount of exactly 0 also throws.","triggerScenarios":"Calling source.Skip(0), source.Skip(-1), or source.Skip(count) where count is computed from user input or a config value that can be zero/negative.","commonSituations":"A 'skip first N items' feature where N is user-configurable and defaults to or can be set to 0; an off-by-one producing a negative; reusing the same variable for both skip and take and letting it hit 0.","solutions":["If you want all items, skip the Skip call entirely when count <= 0.","Clamp the count: source.Skip(Math.Max(1, count)) only when you genuinely want to skip at least one.","Validate count > 0 before calling and surface a clearer error to your caller."],"exampleFix":"// before\nvar filtered = source.Skip(skipCount); // throws when skipCount == 0\n// after\nvar filtered = skipCount > 0 ? source.Skip(skipCount) : source;","handlingStrategy":"validation","validationCode":"if (skipCount <= 0) throw new ArgumentOutOfRangeException(nameof(skipCount));\nvar s = skipCount > 0 ? source.Skip(skipCount) : source;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Branch around Skip when the count is data-driven and can be 0.","Clamp user-supplied counts to >= 1 when 'skip at least one' is the intent.","Remember Skip(0) throws — it is not a no-op in this implementation."],"tags":["reactive","argument-validation","skip","off-by-one"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}