{"record":{"id":"e34fb56677fdfb8b","repo":"Cysharp/UniTask","slug":"error","errorCode":null,"errorMessage":"error","messagePattern":"error","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/UniTask/Assets/Plugins/UniTask/Runtime/UniTaskObservableExtensions.cs","lineNumber":426,"sourceCode":"                isStopped = true;\n                v = lastValue;\n                hv = hasValue;\n            }\n\n            if (hv)\n            {\n                old.OnNext(v);\n                old.OnCompleted();\n            }\n            else\n            {\n                old.OnCompleted();\n            }\n        }\n\n        public void OnError(Exception error)\n        {\n            if (error == null) throw new ArgumentNullException(\"error\");\n\n            IObserver<T> old;\n            lock (observerLock)\n            {\n                ThrowIfDisposed();\n                if (isStopped) return;\n\n                old = outObserver;\n                outObserver = EmptyObserver<T>.Instance;\n                isStopped = true;\n                lastError = error;\n            }\n\n            old.OnError(error);\n        }\n\n        public void OnNext(T value)\n        {","sourceCodeStart":408,"sourceCodeEnd":444,"githubUrl":"https://github.com/Cysharp/UniTask/blob/ceac8d6946b1125fe782cd171fbcb245b567dbf9/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTaskObservableExtensions.cs#L408-L444","documentation":"Thrown by AsyncSubject<T>.OnError(Exception) (line 426) when the supplied exception is null. This enforces the Reactive Extensions contract that OnError must never receive null — an error sequence must carry an actual error — using ArgumentNullException(\"error\"). The subject is the one returned from UniTask<T>.ToObservable().","triggerScenarios":"Calling OnError(null) on the subject returned from ToObservable(), or wiring an upstream Rx source/observer that incorrectly propagates a null exception into OnError.","commonSituations":"Manually driving an AsyncSubject with an exception that resolved to null (e.g. a factory returning null on success); a broken custom IObservable that calls observer.OnError(null); forwarding an unchecked exception variable.","solutions":["Pass a real Exception instance to OnError; never null.","If you have no concrete error, complete the sequence with OnCompleted() instead of OnError.","Null-check the exception at the boundary before forwarding it into OnError."],"exampleFix":"// before\nsubject.OnError(GetErrorOrNull()); // null -> throws ArgumentNullException\n\n// after\nvar ex = GetErrorOrNull();\nif (ex != null) subject.OnError(ex);\nelse subject.OnCompleted();","handlingStrategy":"validation","validationCode":"if (error == null) throw new ArgumentException(\"error must not be null\", nameof(error));\nsubject.OnError(error);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never forward a possibly-null exception into OnError; call OnCompleted if there is no real error.","Sanitize exceptions from untrusted sources before piping them into Rx observers.","Keep the Rx contract in mind: OnNext may receive null values but OnError may not receive a null error."],"tags":["observable","argumentnullexception","unitask","rx","validation"],"backgroundTag":null,"analyzedSha":"ceac8d6946b1125fe782cd171fbcb245b567dbf9","analyzedAt":"2026-08-13T19:16:39.025Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}