2

Having a simple Rxjs stream, i faced this situation:

Rx.Observable
  .fromArray([1,2,3,4,5,6])
// if commented from here 
  .windowWithCount(2, 1)
  .selectMany(function(x) {
    return x.toArray();
  })
// to here .. the error bubbles up
  .subscribe(function(x) {
    console.log('x:',x)
    throw new Error("AAHAAHHAHA!");  
  });

with the windowWithCount + selectMany the error is silently catched internally and isn't catchable and it isn't notified in console neither

commenting those 2 blocks the error is notified on console at least
I don't think this is supposed to be, or am i missing something?
here the jsbin

aleclofabbro
  • 1,635
  • 1
  • 18
  • 35
  • Also instead of `windowWithCount(2, 1).selectMany(...)` you can use http://xgrommx.github.io/rx-book/content/observable/observable_instance_methods/bufferwithcount.html – xgrommx Jun 11 '15 at 12:27

1 Answers1

4

Your subscribe function should never throw an exception. RxJs models asynchronous streams of information, where the observer code often runs asynchronously from the producer code (e.g. not on the same callstack). You cannot depend upon errors propagating back up to the producer.

Rx.Observable
  .fromArray([1,2,3,4,5,6])
// if commented from here 
  .windowWithCount(2, 1)
  .selectMany(function(x) {
    return x.toArray();
  })
// to here .. the error bubbles up
  .subscribe(function(x) {
    try {
      console.log('x:',x)
      throw new Error("AAHAAHHAHA!");
    }
    catch (e) { console.log('error: ' + e); }
  });

That being said, it looks like RxJS is "eating" this particular exception, which may be a bug. RxJS does its best to raise unobserved exceptions as unhandled exceptions in the host. Looks like in this instance this mechanism isn't working. You should open an issue on GitHub.

Brandon
  • 38,310
  • 8
  • 82
  • 87
  • That stands, I shouldn't expect an onerror.. i actually faced this issue with a typo in the `subscribe` like `prp.func()` instead of `prop.func()` resulting in an access from an `undefined` but i couldn't find the problem because of the total silence of the console.. i guess that shouldn't be otherways developing with Rxjs would be a doom – aleclofabbro Jun 11 '15 at 16:46
  • yeah RxJS should have thrown the exception so that the host would eventually see it as an unhandled exception so you'd see it *somewhere*. You should log an issue. – Brandon Jun 11 '15 at 16:49
  • That's just an old version bug! [github issues](https://github.com/Reactive-Extensions/RxJS/issues/759) – aleclofabbro Jun 12 '15 at 08:20