{"record":{"id":"6c789b05978d47bb","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-sources-catch","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'sources')","messagePattern":"Value cannot be null\\. \\(Parameter 'sources'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/Catch.cs","lineNumber":82,"sourceCode":"            return Create(\n                first,\n                second,\n                static async (first, second, observer) =>\n                {\n                    var (sink, inner) = AsyncObserver.Catch(observer, second);\n\n                    var subscription = await first.SubscribeSafeAsync(sink).ConfigureAwait(false);\n\n                    return StableCompositeAsyncDisposable.Create(subscription, inner);\n                });\n        }\n\n        public static IAsyncObservable<TSource> Catch<TSource>(params IAsyncObservable<TSource>[] sources) => Catch((IEnumerable<IAsyncObservable<TSource>>)sources);\n\n        public static IAsyncObservable<TSource> Catch<TSource>(this IEnumerable<IAsyncObservable<TSource>> sources)\n        {\n            if (sources == null)\n                throw new ArgumentNullException(nameof(sources));\n\n            return Create<TSource>(async observer =>\n            {\n                var enumerator = sources.GetEnumerator();\n\n                if (!enumerator.MoveNext())\n                {\n                    return AsyncDisposable.Nop; // REVIEW: Is Never behavior right here?\n                }\n\n                var source = enumerator.Current;\n\n                var (sink, inner) = AsyncObserver.Catch(observer, enumerator);\n\n                var subscription = await source.SubscribeSafeAsync(sink).ConfigureAwait(false);\n\n                return StableCompositeAsyncDisposable.Create(subscription, inner);\n            });","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Catch.cs#L64-L100","documentation":"The params / IEnumerable overload Catch(sources) validates the sources collection itself before enumerating it. A null array or null IEnumerable<IAsyncObservable<TSource>> gives no sources to try, so the operator throws ArgumentNullException named 'sources'.","triggerScenarios":"Calling Catch() with a null array, or passing a null IEnumerable built from a filter/lookup (e.g. sources?.ToArray() returning null), or invoking the params overload with a single null-cast argument like Catch((IAsyncObservable<TSource>[])null).","commonSituations":"Dynamic lists of failover sources that turn out null, LINQ chains assigned to a nullable variable, or params arrays built conditionally and never initialized.","solutions":["Ensure the collection is non-null before calling; use an empty array to mean 'no sources'","Coalesce with Array.Empty<IAsyncObservable<TSource>>() or Enumerable.Empty<TSource>()","Inspect the expression producing the collection for null-returning paths"],"exampleFix":"// before\nvar result = AsyncObservable.Catch(sourcesOrNull);\n// after\nvar result = AsyncObservable.Catch(sourcesOrNull ?? Array.Empty<IAsyncObservable<int>>());","handlingStrategy":"validation","validationCode":"if (sources is null) throw new ArgumentNullException(nameof(sources));","typeGuard":"bool HasSources<T>(IEnumerable<IAsyncObservable<T>> sources) => sources != null;","tryCatchPattern":"try { var result = AsyncObservable.Catch(sources); } catch (ArgumentNullException ex) { /* ex.ParamName == \"sources\"; use empty array */ }","preventionTips":["Use Array.Empty<T>() / Enumerable.Empty<T>() instead of null for 'no sources'","Avoid ?. chains that silently yield null arrays","Assert collection non-null at pipeline boundaries"],"tags":["argument-null","rx","catch-operator"],"backgroundTag":"null-argument","analyzedSha":"94b5d5ab912789f5abe9a72138a25bbd716fe59c","analyzedAt":"2026-09-15T02:26:24.759Z","contentChangedAt":"2026-09-15T02:26:24.759Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}