Scan, Aggregate, Do and DistinctUntilChanged throw callback exceptions to the producer instead of delivering OnError
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 51/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- csharp
- Lĩnh vực
- backend-api-design
Hướng nghiên cứu
Start in src/Primitives.Shared/SignalOperatorParityMixins.RxNames.cs, then trace the forwarding calls to FoldSignal, ReduceSignal, TapSignal, UniqueSignal and UniqueBySignal; compare their callback handling with Select and Where. Add or locate tests for callback exceptions and downstream observer exceptions. Done means callback exceptions reach OnError and stop the subscription, while observer exceptions still reach the producer.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
Some operators handle an exception thrown by a user callback differently from Select and Where. Select and Where deliver it to the subscriber as OnError and end the subscription, as System.Reactive does. Scan, Aggregate, Do, DistinctUntilChanged(comparer) and DistinctUntilChangedBy do not. They throw the exception to the code that called the source's OnNext, the subscriber never gets OnError, and the subscription stays active, so the callback runs again on the next value.
These operators are the System.Reactive-named parity aliases, so code written against Rx expects the Rx behaviour.
Repro (ReactiveUI.Primitives 9.0.0, net10.0)
using ReactiveUI.Primitives;
using ReactiveUI.Primitives.Signals;
static void Probe(string name, Func<IObservable<int>, IObservable<int>> op)
{
var subject = new Signal<int>();
string outcome = "nothing";
op(subject).Subscribe(v => outcome = "OnNext " + v, e => outcome = "OnError " + e.Message, () => outcome = "OnCompleted");
try { subject.OnNext(1); }
catch (Exception e) { outcome = "thrown to OnNext caller: " + e.Message + " (subscriber saw " + outcome + ")"; }
string after;
try { subject.OnNext(2); after = outcome; } catch (Exception e) { after = "second OnNext threw " + e.Message; }
Console.WriteLine($"{name,-38} {outcome} | after: {after}");
}
var boom = new InvalidOperationException("boom");
Probe("Select(selector throws)", s => s.Select<int, int>(_ => throw boom));
Probe("Where(predicate throws)", s => s.Where(_ => throw boom));
Probe("Scan(accumulator throws)", s => s.Scan(0, (_, _) => throw boom));
Probe("Aggregate(accumulator throws)", s => s.Aggregate(0, (_, _) => throw boom));
Probe("Do(onNext throws)", s => s.Do(_ => throw boom));
Probe("DistinctUntilChanged(comparer throws)", s => s.DistinctUntilChanged(new ThrowingComparer()));
Probe("DistinctUntilChangedBy(key throws)", s => s.DistinctUntilChangedBy<int, int>(_ => throw boom));
sealed class ThrowingComparer : IEqualityComparer<int>
{
public bool Equals(int x, int y) => throw new InvalidOperationException("boom");
public int GetHashCode(int obj) => throw new InvalidOperationException("boom");
}
Output:
Select(selector throws) OnError boom | after: OnError boom
Where(predicate throws) OnError boom | after: OnError boom
Scan(accumulator throws) thrown to OnNext caller: boom (subscriber saw nothing) | after: second OnNext threw boom
Aggregate(accumulator throws) thrown to OnNext caller: boom (subscriber saw nothing) | after: second OnNext threw boom
Do(onNext throws) thrown to OnNext caller: boom (subscriber saw nothing) | after: second OnNext threw boom
DistinctUntilChanged(comparer throws) OnNext 1 | after: second OnNext threw boom
DistinctUntilChangedBy(key throws) thrown to OnNext caller: boom (subscriber saw nothing) | after: second OnNext threw boom
DistinctUntilChanged emits the first value because it doesn't compare it to anything; the comparer exception happens on the second value.
Rx comparison
In System.Reactive, Scan, Aggregate, Do, DistinctUntilChanged(comparer) and DistinctUntilChanged(keySelector) all catch exceptions from the user callback (accumulator, onNext action, comparer, key selector). They pass the exception to the downstream observer's OnError and stop. That is what this library's Select and Where already do.
Location
The aliases are in src/Primitives.Shared/SignalOperatorParityMixins.RxNames.cs. They forward to FoldSignal (Scan), ReduceSignal (Aggregate), TapSignal (Do), UniqueSignal (DistinctUntilChanged) and UniqueBySignal (DistinctUntilChangedBy). Those implementations call the callback without the try/OnError handling that Select/Where use.
Suggested fix
Wrap the callback calls in these operators the same way Select/Where do. Catch the exception, mark the operator stopped, and deliver OnError downstream. Exceptions thrown by the downstream observer itself should still go to the producer, not be turned into OnError.
Context
Runic-Artifex's DynamicData fork for ReactiveUI.Primitives currently ships its own replacements for Scan, Do and DistinctUntilChanged to get the Rx behaviour.
- Ngôn ngữ chính
- C#
- Star
- 15
- Fork
- 4
- Merge trung bình
- 8 giờ 56 phút
- Pull request đã merge (30 ngày)
- 5
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của reactiveui/Primitives
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
reactiveui/Primitives#216 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
reactiveui/Primitives#154 · 11 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Dependency DashboardĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
reactiveui/Primitives#47 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của reactiveui/Primitives
Issue tương tự
-
area: core priority: low type: bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
RicoSuter/Namotion.Interceptor#863 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area-cli
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
0.3.0
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
Maintainer thường phản hồi trong vòng 2 ngày
-
[Bug] Decompression leaves metadata that makes recompression throw and corrupt the content typeĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
BrighterCommand/Brighter#4683 ·
Maintainer thường phản hồi trong vòng 1 ngày