Skip to content

[Bug]: Operator Switch does not propagate errors to the downstream#966

Description

@dmalukov

Describe the bug 馃悶

I鈥檝e described the problem in the test case below.

In summary, the Switch operator disrupts error propagation and suppresses exceptions.
In my case, these exceptions are not caught by RxApp.DefaultExceptionHandler either, causing the app to crash.

The operator's documentation does not mention this behavior, so I consider it a bug.

Step to reproduce

    [Fact]
    public void PropagatesErrors()
    {
        bool exceptionCaught = false;

        List<List<int>> listOfLists = [[0, 1, 2]];

        listOfLists.ToObservable()
            .ToObservableChangeSet(int (int value) => value)
            .Select(set =>
            {
                throw new Exception();              // Something bad happened here
                return Observable.Return(set);
            })
            .Do(_ => { }, e => { })                 // here the error handler is called
            .Switch()                               // here the exception is swallowed
            .Catch((Exception e) =>                 // this code will never be executed
            {
                exceptionCaught = true;
                return Observable.Empty<IChangeSet<int, int>>();
            })
            .Subscribe();

        Assert.True(exceptionCaught);
    }

Reproduction repository

https://github.com/dmalukov/DynamicDataSwitchRepro

Expected behavior

The error should be propagated and not swallowed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions