You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm having trouble getting proper stack traces / exception root cause info. Below is an example test:
I have a multi-value observable and I call "SingleAsync" on it, which raises an exception that there is more than one element in the sequence. However, no matter how I try, I can never get the real location of that exception, which makes it basically impossible to track down in our actual system. For example all I get is:
when I await the Observable:
System.InvalidOperationException: Sequence contains more than one element.
at System.Reactive.PlatformServices.ExceptionServicesImpl.Rethrow(Exception exception) in /_/Rx.NET/Source/src/System.Reactive/Internal/ExceptionServicesImpl.cs:line 16
when I await the Observable.ToTask:
System.InvalidOperationException: Sequence contains more than one element.
at TestAwaitOnMultipleElements() in \ReactiveTests.cs:line 29
(i.e. the await task line, not the actual SingleAsync() line)
when I use the Subscribe:
System.InvalidOperationException: Sequence contains more than one element.
(i.e. no stack trace at all)
This is the test code:
[TestMethod]
public async Task TestAwaitOnMultipleElements()
{
IObservable<int> multiElementObservable = OtherMethodToVerifyWeCanFindTheCause();
await multiElementObservable;
var task = multiElementObservable.ToTask();
await task;
TaskCompletionSource<Unit> taskCompletion = new TaskCompletionSource<Unit>();
multiElementObservable.Subscribe(
i => Trace.TraceInformation("Element {0}", i.ToString()),
e =>
{
Trace.TraceError(e.ToString());
taskCompletion.SetException(e);
},
() => taskCompletion.SetResult(Unit.Default));
await taskCompletion.Task;
}
private static IObservable<int> OtherMethodToVerifyWeCanFindTheCause()
{
var multiElementObservable = Observable.Range(0, 2);
multiElementObservable = multiElementObservable
.Do(i => Trace.TraceInformation("Element {0}", i.ToString()))
.SingleAsync(); //this will be an error because there are multiple elements
return multiElementObservable;
}
The text was updated successfully, but these errors were encountered:
Some improvement can likely be made for operators that create an exception object out of nowhere. Those lack stack traces because they don't really got thrown; they're just exception objects flowing into OnError calls. Will have a look for the upcoming release.
A small improvement has been made. The very nature of exception propagation in Rx limits the context provided in a stack trace in cases where an operator such as SingleAsync propagates an exception of its own. However, with the change made (see PR linked above), there will be at least a hint at the operator that caused the exception.
I'm having trouble getting proper stack traces / exception root cause info. Below is an example test:
I have a multi-value observable and I call "SingleAsync" on it, which raises an exception that there is more than one element in the sequence. However, no matter how I try, I can never get the real location of that exception, which makes it basically impossible to track down in our actual system. For example all I get is:
when I await the Observable:
when I await the Observable.ToTask:
(i.e. the
await task
line, not the actual SingleAsync() line)when I use the Subscribe:
This is the test code:
The text was updated successfully, but these errors were encountered: