Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rethrow unhandled errors #149

Merged
merged 1 commit into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Kinetic/Linq/Observable.Subscribe.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Runtime.ExceptionServices;
using Kinetic.Linq.StateMachines;

namespace Kinetic.Linq;
Expand Down Expand Up @@ -68,7 +69,10 @@ public void Dispose() =>
_box = null;

public void OnCompleted() { }
public void OnError(Exception error) { }

public void OnError(Exception error) =>
ExceptionDispatchInfo.Capture(error).Throw();

public void OnNext(T value) { }
}
}
20 changes: 16 additions & 4 deletions test/Kinetic.Tests/ObservableViewTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,19 +345,25 @@ public void OnItemAdded()

using var changes = list
.Changed
.Do(_ => handledBefore = true)
.Do(change => SetWhenAdded(change, ref handledBefore))
.OnItemAdded(item =>
{
Assert.True(handledBefore);
Assert.False(handledAfter);
})
.Do(_ => handledAfter = true)
.Do(change => SetWhenAdded(change, ref handledAfter))
.Subscribe();

list.Add(0);

Assert.True(handledBefore);
Assert.True(handledAfter);

static void SetWhenAdded<T>(ListChange<T> change, ref bool flag)
{
if (change.Action is ListChangeAction.Insert or ListChangeAction.Replace)
flag = true;
}
}

[Fact]
Expand All @@ -369,19 +375,25 @@ public void OnItemRemoved()

using var changes = list
.Changed
.Do(_ => handledBefore = true)
.Do(change => SetWhenRemoved(change, ref handledBefore))
.OnItemRemoved(item =>
{
Assert.True(handledBefore);
Assert.True(handledAfter);
})
.Do(_ => handledAfter = true)
.Do(change => SetWhenRemoved(change, ref handledAfter))
.Subscribe();

list.Add(0);

Assert.True(handledBefore);
Assert.True(handledAfter);

static void SetWhenRemoved<T>(ListChange<T> change, ref bool flag)
{
if (change.Action is ListChangeAction.Remove or ListChangeAction.RemoveAll or ListChangeAction.Replace)
flag = true;
}
}

[Fact]
Expand Down
Loading