Cysharp/UniTask · error · ArgumentNullException
error
Error message
error
What it means
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().
Source
Thrown at src/UniTask/Assets/Plugins/UniTask/Runtime/UniTaskObservableExtensions.cs:426
isStopped = true;
v = lastValue;
hv = hasValue;
}
if (hv)
{
old.OnNext(v);
old.OnCompleted();
}
else
{
old.OnCompleted();
}
}
public void OnError(Exception error)
{
if (error == null) throw new ArgumentNullException("error");
IObserver<T> old;
lock (observerLock)
{
ThrowIfDisposed();
if (isStopped) return;
old = outObserver;
outObserver = EmptyObserver<T>.Instance;
isStopped = true;
lastError = error;
}
old.OnError(error);
}
public void OnNext(T value)
{View on GitHub (pinned to ceac8d6946)
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.
Example fix
// before subject.OnError(GetErrorOrNull()); // null -> throws ArgumentNullException // after var ex = GetErrorOrNull(); if (ex != null) subject.OnError(ex); else subject.OnCompleted();
Defensive patterns
Strategy: validation
Validate before calling
if (error == null) throw new ArgumentException("error must not be null", nameof(error));
subject.OnError(error); Prevention
- 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.
When it happens
Trigger: Calling OnError(null) on the subject returned from ToObservable(), or wiring an upstream Rx source/observer that incorrectly propagates a null exception into OnError.
Common situations: 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.
Related errors
- observer
- AsyncSubject is not completed yet
- Disposable is already set
- Can not trigger itself in iterating.
- handler
AI-assisted analysis of Cysharp/UniTask@ceac8d6946 (2026-08-13).
Data as JSON: /api/errors/e34fb56677fdfb8b.
Report an issue: GitHub.