{"record":{"id":"ea6e155cdfc2ae59","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-onerror-do","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'onError')","messagePattern":"Value cannot be null\\. \\(Parameter 'onError'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Ix.NET/Source/System.Interactive/System/Linq/Operators/Do.cs","lineNumber":63,"sourceCode":"            return DoCore(source, onNext, _ => { }, onCompleted);\n        }\n\n        /// <summary>\n        /// Lazily invokes an action for each value in the sequence, and executes an action upon exceptional termination.\n        /// </summary>\n        /// <typeparam name=\"TSource\">Source sequence element type.</typeparam>\n        /// <param name=\"source\">Source sequence.</param>\n        /// <param name=\"onNext\">Action to invoke for each element.</param>\n        /// <param name=\"onError\">Action to invoke on exceptional termination of the sequence.</param>\n        /// <returns>Sequence exhibiting the specified side-effects upon enumeration.</returns>\n        public static IEnumerable<TSource> Do<TSource>(this IEnumerable<TSource> source, Action<TSource> onNext, Action<Exception> onError)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n            if (onNext == null)\n                throw new ArgumentNullException(nameof(onNext));\n            if (onError == null)\n                throw new ArgumentNullException(nameof(onError));\n\n            return DoCore(source, onNext, onError, () => { });\n        }\n\n        /// <summary>\n        /// Lazily invokes an action for each value in the sequence, and executes an action upon successful or exceptional\n        /// termination.\n        /// </summary>\n        /// <typeparam name=\"TSource\">Source sequence element type.</typeparam>\n        /// <param name=\"source\">Source sequence.</param>\n        /// <param name=\"onNext\">Action to invoke for each element.</param>\n        /// <param name=\"onError\">Action to invoke on exceptional termination of the sequence.</param>\n        /// <param name=\"onCompleted\">Action to invoke on successful termination of the sequence.</param>\n        /// <returns>Sequence exhibiting the specified side-effects upon enumeration.</returns>\n        public static IEnumerable<TSource> Do<TSource>(this IEnumerable<TSource> source, Action<TSource> onNext, Action<Exception> onError, Action onCompleted)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Ix.NET/Source/System.Interactive/System/Linq/Operators/Do.cs#L45-L81","documentation":"The Do(source, onNext, onError) overload requires a non-null onError action and throws ArgumentNullException with parameter name 'onError' when it is null. onError is invoked on exceptional termination of the sequence, and the library rejects a null eagerly at the call site.","triggerScenarios":"Calling `source.Do(x => Log(x), null)` or `source.Do(x => Log(x), null, () => Done())`; a conditionally assigned error handler that ends up null.","commonSituations":"Optional error logging configured off in some environments leaving the handler null; refactoring where the onError lambda was removed but the call retained its slot; DI-resolved handlers missing a registration.","solutions":["Pass a no-op `_ => { }` for onError if error notification is not needed","Use the Do(source, onNext) overload which supplies an internal error handler","Default the handler: `onError ??= _ => { };` before calling","Register/assign the error handler in the DI container or configuration path that produces it"],"exampleFix":"// before\nvar result = source.Do(x => Log(x), null);\n// after\nvar result = source.Do(x => Log(x), _ => { });","handlingStrategy":"validation","validationCode":"if (onError is null) onError = static _ => { };","typeGuard":"static Action<Exception> NonNullErrorHandler(Action<Exception>? h) => h ?? (static _ => { });","tryCatchPattern":"try { var result = source.Do(x => Log(x), onError!); ... }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"onError\") { Log(\"onError callback missing; using no-op\"); }","preventionTips":["Default error handlers at composition time with ??=","Do not disable error reporting by passing null; wrap the handler body in environment checks instead","Prefer overloads that supply internal no-op handlers when error handling is unneeded","Centralize pipeline construction so handler wiring is tested once"],"tags":["argumentnull","linq","dotnet","error-handler"],"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"}